This repository has been archived on 2026-05-27. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
rustypipe/src/macros.rs

50 lines
1.1 KiB
Rust

/// Returns an unwrapped Option if Some() otherwise returns the passed expression
#[allow(unused_macros)]
macro_rules! some_or_bail {
($opt:expr, $ret:expr $(,)?) => {{
match $opt {
Some(stuff) => stuff,
None => {
return $ret;
}
}
}};
}
/// Returns an unwrapped Option if Some() otherwise continues a loop.
#[allow(unused_macros)]
macro_rules! some_or_continue {
($opt:expr $(,)?) => {{
match $opt {
Some(stuff) => stuff,
None => {
continue;
}
}
}};
}
/// Returns an unwrapped Result if Ok() otherwise returns the passed expression
#[allow(unused_macros)]
macro_rules! ok_or_bail {
($result:expr, $ret:expr $(,)?) => {{
match $result {
Ok(stuff) => stuff,
Err(_) => {
return $ret;
}
}
}};
}
#[allow(unused_macros)]
macro_rules! ok_or_continue {
($opt:expr $(,)?) => {{
match $opt {
Ok(stuff) => stuff,
Err(_) => {
continue;
}
}
}};
}