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