init: it builds

This commit is contained in:
鲁树人
2024-09-02 21:01:19 +01:00
commit ff11a8186e
23 changed files with 1073 additions and 0 deletions

19
um_wasm/src/lib.rs Normal file
View File

@@ -0,0 +1,19 @@
mod utils;
use utils::set_panic_hook;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
fn alert(s: &str);
}
#[wasm_bindgen]
pub fn init() {
set_panic_hook();
}
#[wasm_bindgen]
pub fn greet() {
alert("hello world!");
}

10
um_wasm/src/utils.rs Normal file
View File

@@ -0,0 +1,10 @@
pub fn set_panic_hook() {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then
// we will get better error messages if our code ever panics.
//
// For more details see
// https://github.com/rustwasm/console_error_panic_hook#readme
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
}