Macro vesta::case[][src]

case!() { /* proc-macro */ }

Match on the cases of a value implementing Match.

This macro is the safe and efficient way to match on something; it is faster than using chains of try_case, but safe because it ensures exhaustiveness when required.

Syntax for this macro is very similar to the syntax for match in Rust, except constructor names are replaced with their corresponding numerals, as defined by implementations of Case.

Omitting a parenthesized pattern after a numeral N is equivalent to the pattern N(_), i.e. the pattern matching all values tagged with N.


use vesta::case;

let option = Some("thing");

case!(option {
    0 => assert!(false),
    1(s) => assert_eq!(s, "thing"),