-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlib.rs
More file actions
57 lines (48 loc) · 1.56 KB
/
lib.rs
File metadata and controls
57 lines (48 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#![cfg_attr(docsrs, feature(doc_cfg))]
#![warn(missing_debug_implementations, missing_docs, rust_2018_idioms)]
#![deny(unreachable_pub)]
#![deny(private_bounds)]
#![deny(rustdoc::private_intra_doc_links)]
#![deny(private_interfaces)]
//! {{project-name}}
use wasm_bindgen::prelude::wasm_bindgen;
/// Add two integers together.
#[wasm_bindgen]
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
//------------------------------------------------------------------------------
// Utilities
//------------------------------------------------------------------------------
/// Panic hook lets us get better error messages if our Rust code ever panics.
///
/// For more details see
/// <https://github.com/rustwasm/console_error_panic_hook#readme>
#[wasm_bindgen(js_name = "setPanicHook")]
pub fn set_panic_hook() {
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
}
#[wasm_bindgen]
extern "C" {
/// For alerting
pub(crate) fn alert(s: &str);
/// For logging in the console.
#[wasm_bindgen(js_namespace = console)]
pub fn log(s: &str);
}
//------------------------------------------------------------------------------
// Macros
//------------------------------------------------------------------------------
/// Return a representation of an object owned by JS.
#[macro_export]
macro_rules! value {
($value:expr) => {
wasm_bindgen::JsValue::from($value)
};
}
/// Calls the wasm_bindgen console.log.
#[macro_export]
macro_rules! console_log {
($($t:tt)*) => ($crate::log(&format_args!($($t)*).to_string()))
}