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.

113 lines
2.2 KiB

/// Unwrap a Result, and log the error.
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.
5 years ago
#[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<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
5 years ago
#[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);
// }
// };
// }