You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.6 KiB

5 years ago
#[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));
}
5 years ago
}
};
}
/// Unwrap a Result<T, E>, 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);
}
}
};
}
#[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);
// }
// };
// }