Skip to content

Commit a6aa39e

Browse files
iamcodemakersendilkumarn
authored andcommitted
set a panic hook conditionally (#21)
* set a panic hook conditionally Set a panic hook conditionally depending on if feature console_error_panic_hook is enabled or not. * inline the empty set_panic_hook_call
1 parent 3422e36 commit a6aa39e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

crate/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ cfg_if! {
1111
if #[cfg(feature = "console_error_panic_hook")] {
1212
extern crate console_error_panic_hook;
1313
use console_error_panic_hook::set_once as set_panic_hook;
14+
} else {
15+
#[inline]
16+
fn set_panic_hook() {}
1417
}
1518
}
1619

@@ -27,6 +30,10 @@ cfg_if! {
2730
// Called by our JS entry point to run the example
2831
#[wasm_bindgen]
2932
pub fn run() -> Result<(), JsValue> {
33+
// If the `console_error_panic_hook` feature is enabled this will set a panic hook, otherwise
34+
// it will do nothing.
35+
set_panic_hook();
36+
3037
// Use `web_sys`'s global `window` function to get a handle on the global
3138
// window object.
3239
let window = web_sys::window().expect("no global `window` exists");

0 commit comments

Comments
 (0)