Hello, World in Rust WASM
April 2026
This is a basic `Hello, World` WASM
app written in rust.
Rust
Cargo.toml
[package]
name = "hello-world"
version = "0.1.0"
edition = "2024"
[lib]
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "0.2.116"
src/lib.rs
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn hello_world() -> String {
"Hello, world!".to_string()
}
build script
wasm-pack build --target web
HTML
page.html
<script type="module" src="/rust/wasm/hello-world/hello-world.js"></script>
<div id="output"></div>
JavaScript
hello-world.js
import init, { hello_world } from "./pkg/hello_world.js";
async function main() {
await init();
const el = document.querySelector("#output");
el.innerHTML = hello_world();
}
main();
Output