#![doc(
html_logo_url = "https://libcala.github.io/logo.svg",
html_favicon_url = "https://libcala.github.io/icon.svg",
html_root_url = "https://docs.rs/devout"
)]
#![deny(unsafe_code)]
#![warn(
anonymous_parameters,
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
nonstandard_style,
rust_2018_idioms,
single_use_lifetimes,
trivial_casts,
trivial_numeric_casts,
unreachable_pub,
unused_extern_crates,
unused_qualifications,
variant_size_differences
)]
#[derive(Copy, Clone, Debug)]
pub struct Tag(Option<&'static str>);
impl Tag {
#[inline(always)]
pub const fn new(ident: &'static str) -> Self {
Tag(Some(ident))
}
#[inline(always)]
pub const fn hide(self) -> Self {
Tag(None)
}
#[inline(always)]
pub const fn show(self, log: bool) -> Self {
if log {
self
} else {
self.hide()
}
}
#[inline(always)]
pub const fn is_shown(self) -> bool {
self.0.is_some()
}
#[inline(always)]
const fn as_option(&self) -> Option<&'static str> {
self.0
}
#[inline(always)]
pub fn log(&self, args: std::fmt::Arguments<'_>) {
if let Some(tag) = self.as_option() {
#[cfg(not(target_arch = "wasm32"))]
let _ = <std::io::Stdout as std::io::Write>::write_fmt(
&mut std::io::stdout(),
format_args!("[{}] {}\n", tag, args),
);
#[cfg(target_arch = "wasm32")]
web_sys::console::log_1(&wasm_bindgen::JsValue::from_str(&format!(
"[{}] {}",
tag, args
)));
}
}
}
#[macro_export]
macro_rules! log {
($tag:ident) => {{
$tag.log(format_args!(""));
}};
($tag:ident, $($arg:tt)*) => {{
$tag.log(format_args!($($arg)*));
}};
}