Created
March 27, 2022 12:33
-
-
Save qtfkwk/2eff0859fee5a083d31c75d4dc621b85 to your computer and use it in GitHub Desktop.
Fix seed-rs' weird debug, log, warn, error macros...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 1. Add the following to your seed-rs project's src/lib.rs: | |
| use web_sys::console; | |
| const ENABLE_CONSOLE_DEBUG: bool = true; | |
| const ENABLE_CONSOLE_LOG: bool = true; | |
| const ENABLE_CONSOLE_WARN: bool = true; | |
| const ENABLE_CONSOLE_ERROR: bool = true; | |
| macro_rules! debug { | |
| ($($x:tt)*) => (if ENABLE_CONSOLE_DEBUG { | |
| console::debug_1(&JsValue::from_str(&format!($($x)*))); | |
| }); | |
| } | |
| macro_rules! log { | |
| ($($x:tt)*) => (if ENABLE_CONSOLE_LOG { | |
| console::log_1(&JsValue::from_str(&format!($($x)*))); | |
| }); | |
| } | |
| macro_rules! warn { | |
| ($($x:tt)*) => (if ENABLE_CONSOLE_WARN { | |
| console::warn_1(&JsValue::from_str(&format!($($x)*))); | |
| }); | |
| } | |
| macro_rules! error { | |
| ($($x:tt)*) => (if ENABLE_CONSOLE_ERROR { | |
| console::error_1(&JsValue::from_str(&format!($($x)*))); | |
| }); | |
| } | |
| // 2. Then use it like format/println: | |
| debug!("The value of variable is {}.", variable); | |
| log!("The value of variable is {}.", variable); | |
| warn!("The value of variable is {}.", variable); | |
| error!("The value of variable is {}.", variable); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment