RMusicBot/src/macros.rs

48 lines
1 KiB
Rust
Raw Normal View History

2018-08-14 17:08:13 +00:00
#![macro_use]
/// check result macro, where the Ok() is the type which should be returned
#[macro_export]
macro_rules! check_result {
($v:expr) => {
match $v {
Ok(t) => t,
Err(msg) => return Err(msg),
}
};
}
/// check result macro, where the Ok() is the type which should be returned, else print error and return
#[macro_export]
macro_rules! check_result_return {
($v:expr) => {
match $v {
Ok(t) => t,
Err(msg) => {
println!("{}", msg);
return;
}
}
};
}
// check result macro, where the Ok() is void
#[macro_export]
macro_rules! check_error {
($v:expr) => {
if let Err(msg) = $v {
return Err(msg);
};
};
}
/// check result macro, where the Ok() is void, but just print the error message
#[macro_export]
macro_rules! display_error {
($v:expr) => {
if let Err(msg) = $v {
println!("{}", msg);
return;
};
};
}