Macro unwrap::unwrap_err [−][src]
macro_rules! unwrap_err { ($e:expr) => { ... }; ($e:expr, $($arg:tt)*) => { ... }; }
A replacement for calling unwrap_err()
on a Result
.
This macro is intended to be used in all cases where one would unwrap_err
a Result
to
deliberately panic in case of unexpected non-error, e.g. in test-cases. Such unwrap_err
s don't
give a precise point of failure in the code and instead indicate some line number in the Rust
core library. This macro provides a precise point of failure and decorates the failure for easy
viewing.
Examples
let some_result = Err::<u64, String>("Failed".to_string()); let string_length = unwrap_err!(some_result, "This is an optional user-supplied text.").len(); assert_eq!(string_length, 6);