diff --git a/src/macros.rs b/src/macros.rs index 425e02c..4f3636e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -13,6 +13,21 @@ macro_rules! try_log { }; } +/// Unwrap a Result and print if it's an error +#[macro_export] +macro_rules! try_print { + ($e:expr, $($arg:tt)*) => { + match $e { + Ok(r) => r, + Err(e) => { + let s = std::fmt::format(format_args!($($arg)*)); + println!("{}({}) :: {} :: {}", file!(), line!(), s, e); + return Err(Box::from(e)); + } + } + }; +} + /// Unwrap a Result, if it's an error then let client know and return. #[macro_export] macro_rules! try_send_error {