Skip to content

Commit 24d2c5d

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 24d2c5d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ 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+
if self.state == Status::OK {
97+
self.value
98+
} else {
99+
panic!(
100+
"called `StatusAnd::unwrap()` on an error value. Value: {:?}, status: {:?}",
101+
self.value, self.status
102+
);
103+
}
104+
}
105+
}
106+
93107
#[macro_export]
94108
macro_rules! unpack {
95109
($status:ident|=, $e:expr) => {

0 commit comments

Comments
 (0)