#[cfg(not(feature = "runtime_configurable"))]
panic!("The `runtime_configurable` feature must be enabled");
extern crate alloc;
use matched_enums::{match_when, Matched};
#[derive(Matched, PartialEq, Eq, Debug, Ord, PartialOrd)]
#[matched_enum(allow_runtime_configurable=true, value_type=isize)]
enum Foo {
#[matches(..0)]
Bar,
#[matches(0..1)]
Baz,
#[matches(1..)]
Fred,
}
fn main() {
let mut matcher = FooMatcher::<isize>::default();
assert_eq!(matcher.try_into_enum(&-75).unwrap(), Foo::Bar);
assert_eq!(matcher.try_into_enum(&0).unwrap(), Foo::Baz);
assert_eq!(matcher.try_into_enum(&10).unwrap(), Foo::Fred);
matcher.bar = match_when!(100..1000); matcher.baz = Box::new(|&value| (value % 2) == 0); assert_eq!(matcher.try_into_enum(&16).unwrap(), Foo::Baz);
assert_eq!(matcher.try_into_enum(&600).unwrap(), Foo::Bar);
assert_eq!(matcher.try_into_enum(&1001).unwrap(), Foo::Fred);
assert!(matcher.try_into_enum(&-75).is_err());
matcher.bar = match_when!(_);
assert_eq!(matcher.try_into_enum(&16).unwrap(), Foo::Bar);
assert_eq!(matcher.try_into_enum(&600).unwrap(), Foo::Bar);
assert_eq!(matcher.try_into_enum(&1001).unwrap(), Foo::Bar);
const BAR_MAX: isize = 10;
let bar_min = -10;
matcher.bar = Box::new(move |&value| (bar_min..BAR_MAX).contains(&value));
assert_eq!(matcher.try_into_enum(&5).unwrap(), Foo::Bar);
assert_eq!(matcher.try_into_enum(&1001).unwrap(), Foo::Fred);
}