Derive Macro vesta::Match [−][src]
#[derive(Match)]
Derive correct and efficient instances of Match
and Case
for a given struct
or enum
.
Examples
use vesta::{Match, case}; #[derive(Match)] enum T<'a, P> { A, B(i64), C { field: P }, D(&'a str, bool), } fn check<'a>(t: T<'a, usize>) -> bool { case!(t { 0 => true, 1(0) => true, 1(n) => n != 0, 2(u) if u == 6 => u % 2 == 0, 2 => true, 3(s, true) => s.chars().count() % 2 == 0, 3(s, _) => true, }) } use T::*; assert!(check(A)); assert!(check(B(0))); assert!(check(B(1))); assert!(check(C { field: 0 })); assert!(check(C { field: 6 })); assert!(check(D("hello", false))); assert!(check(D("world!", true)));