minimal_rust_wasm/wasm_main.rs
1use wasm_bindgen::prelude::*;
2
3#[wasm_bindgen(start)]
4pub fn main() {
5 let window = web_sys::window().unwrap();
6 let document = window.document().unwrap();
7 let body = document.body().unwrap();
8 let p = document.create_element("p").unwrap();
9
10 p.set_inner_html("Hello, world!");
11 body.append_child(&p).unwrap();
12
13 log("Hello, console!");
14}
15
16#[wasm_bindgen]
17extern {
18 #[wasm_bindgen(js_namespace = console)]
19 fn log(s: &str);
20}