mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-23 05:02:13 +00:00
20 lines
651 B
Rust
20 lines
651 B
Rust
use wasm_bindgen::prelude::*;
|
|
|
|
// Called by our JS entry point to run the example
|
|
#[wasm_bindgen(start)]
|
|
pub fn run() -> 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")?;
|
|
val.set_inner_html("Hello from Rust!");
|
|
|
|
body.append_child(&val)?;
|
|
|
|
Ok(())
|
|
}
|