#[derive(ConstEnum)]Expand description
This function defines the procedural derive macro ConstEnum.
It can be used on any enum with a repr type, e.g. repr(u8).
When being used on an enum, this will automatically add the following implementations:
From<repr_type> for <enum_type>: Convert repr type to enum, panic if invalid valueFrom<enum_type> for <repr_type>: Convert enum to repr type
ยงExample
#![feature(const_trait_impl)]
use const_enum::ConstEnum;
#[derive(Copy, Clone, Debug, Eq, PartialEq, ConstEnum)]
#[repr(u8)]
enum Test {
A = 0b010,
B = 0b100,
C = 0b001
}
pub fn example() {
println!("{:?}", Test::from(0b010 as u8));
println!("{:?}", u8::from(Test::A));
}