here_be_dragons/demo/src/lib.rs

24 lines
714 B
Rust
Raw Normal View History

2020-09-12 12:44:37 +00:00
use wasm_bindgen::prelude::*;
// Called when the wasm module is instantiated
#[wasm_bindgen(start)]
pub fn main() -> Result<(), JsValue> {
// Use `web_sys`'s global `window` function to get a handle on the global
// window object.
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have a document on window");
let body = document.body().expect("document should have a body");
// Manufacture the element we're gonna append
let val = document.create_element("p")?;
2020-09-12 13:10:35 +00:00
val.set_inner_html("Hello from Rust! 1");
2020-09-12 12:44:37 +00:00
body.append_child(&val)?;
Ok(())
}
#[wasm_bindgen]
pub fn add(a: u32, b: u32) -> u32 {
a + b
}