add try_send and option_send macros

master
rasul 5 years ago
parent d915d17bef
commit a0598b4159

@ -47,6 +47,32 @@ macro_rules! try_send_error {
}; };
} }
/// Unwrap a `Result<T, E>`, 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<T>`, 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<Option<T>, E>`, log message if it's error or none /// Unwrap a `Result<Option<T>, E>`, log message if it's error or none
#[macro_export] #[macro_export]
macro_rules! try_option_send_error { macro_rules! try_option_send_error {

Loading…
Cancel
Save