Macro unwrap::unwrap [] [src]

macro_rules! unwrap {
    ($e:expr) => { ... };
    ($e:expr, $($arg:tt)*) => { ... };
}

A replacement for calling unwrap() on a Result or Option.

This macro is intended to be used in all cases where one would unwrap a Result or Option to deliberately panic in case of error, e.g. in test-cases. Such unwraps 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_option = Some("Hello".to_string());
let string_length = unwrap!(some_option, "This is an optional user-supplied text.").len();
assert_eq!(string_length, 5);