inner

Macro ok

Source
macro_rules! ok {
    ($x:expr, if $i:path, else |$e:ident| $b:block) => { ... };
    ($x:expr, if $i:path, else $b:block) => { ... };
    ($x:expr, if $i:path, or |$e:ident| $b:block) => { ... };
    ($x:expr, if $i:path, or $b:block) => { ... };
    ($x:expr, if $i:path) => { ... };
}
Expand description

Converts your enum to an Result.

§Examples

assert_eq!(ok!(Fruit::Apple(15), if Fruit::Apple), Ok(15));
assert_eq!(ok!(Fruit::Orange(5), if Fruit::Apple), Err(Fruit::Orange(5)));

assert_eq!(ok!(Fruit::Orange(5), if Fruit::Apple, or {75}), Err(75));
assert_eq!(ok!(Fruit::Orange(5), if Fruit::Apple, else {Err(75)}), Err(75));