mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
34 lines
780 B
Rust
34 lines
780 B
Rust
#[macro_export]
|
|
macro_rules! time {
|
|
($expr:expr) => {
|
|
$crate::time!(stringify!($expr), $expr)
|
|
};
|
|
($label:expr, $expr:expr) => {
|
|
$crate::time!($expr, "{}", $label)
|
|
};
|
|
($expr:expr, $fmt:expr, $($args:tt)*) => {{
|
|
if tracing::enabled!(tracing::Level::DEBUG) {
|
|
let start = std::time::Instant::now();
|
|
let result = $expr;
|
|
tracing::debug!("{} took {:?}", format_args!($fmt, $($args)*), start.elapsed());
|
|
result
|
|
} else {
|
|
$expr
|
|
}
|
|
}};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! err {
|
|
($expr:expr) => {
|
|
$crate::err!(stringify!($expr), $expr)
|
|
};
|
|
($label:expr, $expr:expr) => {
|
|
$crate::err!($expr, "{}", $label)
|
|
};
|
|
($expr:expr, $fmt:expr, $($args:tt)*) => {{
|
|
if let Err(e) = $expr {
|
|
tracing::error!("{} failed: {e}", format_args!($fmt, $($args)*));
|
|
}
|
|
}};
|
|
}
|