Skip to content

Instantly share code, notes, and snippets.

@goofmint

goofmint/index.rs

Created Oct 5, 2018
Embed
What would you like to do?
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