Skip to content

Commit

Permalink
Add a unwrap() function to StatusAnd.
Browse files Browse the repository at this point in the history
This provides an easy way to get the value and check for errors.
  • Loading branch information
tgross35 committed May 18, 2024
1 parent 7db8595 commit 24d2c5d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ impl<T> StatusAnd<T> {
}
}

impl<T: core::fmt::Debug> StatusAnd<T> {
/// Extract the inner value if there were no errors. If there were errors, panic.
pub fn unwrap(self) -> T {
if self.state == Status::OK {
self.value
} else {
panic!(
"called `StatusAnd::unwrap()` on an error value. Value: {:?}, status: {:?}",
self.value, self.status
);
}
}
}

#[macro_export]
macro_rules! unpack {
($status:ident|=, $e:expr) => {
Expand Down

0 comments on commit 24d2c5d

Please sign in to comment.