4 releases (1 stable)
1.0.0 | Jul 31, 2023 |
---|---|
0.6.0 | Sep 2, 2022 |
0.5.2 | Aug 26, 2022 |
0.5.1 | Aug 26, 2022 |
#2103 in Rust patterns
45 downloads per month
Used in alt-enum
5KB
72 lines
value-enum
Macro for generating enums associated with values.
Example
use value_enum::value_enum;
value_enum!(
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
enum Abc: char {
A = 'a',
B = 'b',
C = 'c',
}
);
assert_eq!(
char::from(Abc::A),
'a'
);
assert_eq!(
Abc::try_from('b'),
Ok(Abc::B)
);
lib.rs
:
Macro for generating enums associated with values.
Example
use value_enum::value_enum;
value_enum!(
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
enum Abc: char {
A = 'a',
B = 'b',
C = 'c',
}
);
assert_eq!(char::from(Abc::A), 'a');
assert_eq!(Abc::try_from('b'), Ok(Abc::B));