/// Unwrap a Result, and log the error. #[macro_export] macro_rules! try_log { ($e:expr, $($arg:tt)*) => { match $e { Ok(r) => r, Err(e) => { let s = std::fmt::format(format_args!($($arg)*)); log::error!("{}({}) :: {} :: {}", file!(), line!(), s, e); return Err(Box::from(e)); } } }; } /// 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 { ($i:ident, $e:expr) => { match $e { Ok(r) => r, Err(e) => { log::error!( "{}({}) :: returning SendQueue::error() :: {}", file!(), line!(), e ); return SendQueue::error($i); } } }; } /// Unwrap a `Result`, send a message if it's E. #[macro_export] macro_rules! try_send { ($i:ident, $e:expr, $($arg:tt)*) => { match $e { Ok(r) => r, Err(_e) => { return SendQueue(vec![($i, std::fmt::format(format_args!($($arg)*)), true)].into()); } } }; } /// Unwrap a `Option`, send a message if it's None. #[macro_export] macro_rules! option_send { ($i:ident, $e:expr, $($arg:tt)*) => { match $e { Some(r) => r, None => { return SendQueue(vec![($i, std::fmt::format(format_args!($($arg)*)), true)].into()); } } }; } /// Unwrap a `Result, E>`, log message if it's error or none #[macro_export] macro_rules! try_option_send_error { ($i:ident, $e:expr) => { match $e { Ok(Some(r)) => r, Ok(None) => { log::error!( "{}({}) :: returning SendQueue::error() :: None value", file!(), line!() ); return SendQueue::error($i); } Err(e) => { log::error!( "{}({}) :: returning SendQueue::error() :: {}", file!(), line!(), e ); return SendQueue::error($i); } } }; } // #[macro_export] // macro_rules! try_option_send_error { // ($i:ident, $e:expr) => { // if let Ok(Some(r)) = $e { // r // } else { // return SendQueue::error($i); // } // }; // }