Skip to content

Instantly share code, notes, and snippets.

@goofmint
Created October 5, 2018 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goofmint/575c64678e762907c779ce30471d1b63 to your computer and use it in GitHub Desktop.
Save goofmint/575c64678e762907c779ce30471d1b63 to your computer and use it in GitHub Desktop.
extern crate wasm_bindgen;
extern crate web_sys;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn run() -> Result<(), JsValue> {
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");
let val = document.create_element("p")?;
val.set_inner_html("Hello from Rust!");
AsRef::<web_sys::Node>::as_ref(&body).append_child(val.as_ref())?;
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment