Skip to content

Instantly share code, notes, and snippets.

@qtfkwk
Created March 27, 2022 12:33
Show Gist options
  • Select an option

  • Save qtfkwk/2eff0859fee5a083d31c75d4dc621b85 to your computer and use it in GitHub Desktop.

Select an option

Save qtfkwk/2eff0859fee5a083d31c75d4dc621b85 to your computer and use it in GitHub Desktop.
Fix seed-rs' weird debug, log, warn, error macros...
// 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