unwrap_opt

Macro unwrap_opt 

Source
macro_rules! unwrap_opt {
    ($option: expr $(,)?) => { ... };
    ($option: expr, $err_code: ident $(,)?) => { ... };
    ($option: expr, $msg: literal $(,)?) => { ... };
    ($option:expr, $err:expr $(,)?) => { ... };
    ($option:expr, $err:expr, $msg: expr $(,)?) => { ... };
}
Expand description

Attempts to unwrap an Option, and if it fails, prints an error.

§Example

let one = 1_u64;
let two = 2_u64;
let my_value = unwrap_opt!(one.checked_sub(2), "cannot do this"); // returns an error