Macro unwrap_to::unwrap_to [] [src]

macro_rules! unwrap_to {
    ($var:expr => $variant:path) => { ... };
}
#[macro_use] extern crate unwrap_to;

enum Rule {
    String(String),
    Number(u64),
}

fn main() {
    let rule = Rule::Number(7);
    assert_eq!(&7, unwrap_to!(rule => Rule::Number));
}

Panics

The macro will panic as unreachable if the variant doesn't match.