impulse/
lib.rs

1extern crate cfg_if;
2extern crate wasm_bindgen;
3extern crate web_sys;
4
5pub mod component;
6mod utils;
7
8use cfg_if::cfg_if;
9use wasm_bindgen::prelude::*;
10
11cfg_if! {
12    // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
13    // allocator.
14    if #[cfg(feature = "wee_alloc")] {
15        extern crate wee_alloc;
16        #[global_allocator]
17        static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
18    }
19}
20
21#[wasm_bindgen(start)]
22pub fn run() -> Result<(), JsValue> {
23    // Use `web_sys`'s global `window` function to get a handle on the global
24    // window object.
25    let window = web_sys::window().expect("no global `window` exists");
26    let document = window.document().expect("should have a document on window");
27    let body = document.body().expect("document should have a body");
28
29    // Manufacture the element we're gonna append
30    let val = document.create_element("p")?;
31    val.set_inner_html("Hello from Impulse!");
32
33    body.append_child(&val)?;
34
35    Ok(())
36}