Skip to content

Commit bd3af16

Browse files
committed
Add a unwrap() function to StatusAnd.
This provides an easy way to get the value and check for errors.
1 parent 7db8595 commit bd3af16

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ impl<T> StatusAnd<T> {
9090
}
9191
}
9292

93+
impl<T: core::fmt::Debug> StatusAnd<T> {
94+
/// Extract the inner value if there were no errors. If there were errors, panic.
95+
pub fn unwrap(self) -> T {
96+
assert_eq!(self.status, Status::OK, "called `StatusAnd::unwrap()` on an error value. Value: {:?}");
97+
self.value
98+
}
99+
}
100+
93101
#[macro_export]
94102
macro_rules! unpack {
95103
($status:ident|=, $e:expr) => {

0 commit comments

Comments
 (0)