Skip to content

Commit

Permalink
Add try_opt and expect macros
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jun 1, 2023
1 parent 4d6e6fe commit 9dc742e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,25 @@ impl fmt::Debug for OutOfRange {

#[cfg(feature = "std")]
impl std::error::Error for OutOfRange {}

/// Workaround because `?` is not (yet) available in const context.
#[macro_export]
macro_rules! try_opt {
($e:expr) => {
match $e {
Some(v) => v,
None => return None,
}
};
}

/// Workaround because `.expect()` is not (yet) available in const context.
#[macro_export]
macro_rules! expect {
($e:expr, $m:literal) => {
match $e {
Some(v) => v,
None => panic!($m),
}
};
}

0 comments on commit 9dc742e

Please sign in to comment.