From ed2a52da4bdf1ebcec39021e85030425a89632bf Mon Sep 17 00:00:00 2001 From: rasul Date: Fri, 3 Apr 2020 18:39:04 -0500 Subject: [PATCH] add try_print!() macro --- src/macros.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 {