X-Git-Url: http://git.euphorik.ch/?p=recipes.git;a=blobdiff_plain;f=frontend%2Fsrc%2Flib.rs;fp=frontend%2Fsrc%2Flib.rs;h=1607fc0c5a2084147d4235d220e3d34a41e698d0;hp=0000000000000000000000000000000000000000;hb=642dd8a80ce2e1212b8e30c1edabb32bdb416cfc;hpb=d28e765e39e70ad2ab9a42885c786d5d8ba9ba40 diff --git a/frontend/src/lib.rs b/frontend/src/lib.rs new file mode 100644 index 0000000..1607fc0 --- /dev/null +++ b/frontend/src/lib.rs @@ -0,0 +1,35 @@ +mod utils; + +use wasm_bindgen::prelude::*; +use web_sys::console; + +// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global +// allocator. +#[cfg(feature = "wee_alloc")] +#[global_allocator] +static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; + +#[wasm_bindgen] +extern { + fn alert(s: &str); +} + +#[wasm_bindgen] +pub fn greet(name: &str) { + alert(&format!("Hello, {}!", name)); + console::log_1(&"Hello bg".into()); +} + +#[wasm_bindgen(start)] +pub fn main() -> 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!"); + + body.append_child(&val)?; + + Ok(()) +} \ No newline at end of file