1 unstable release
0.1.0 | Jan 5, 2019 |
---|
#33 in #bitfield
Used in u8bits
6KB
71 lines
surjective-enum
Rust macro to derive a surjective mapping from enum representation to enum.
Derive a surjective ::core::convert::From conversion function which maps all values which are not part of the enumeration to the last enum discriminant.
The example
use surjective_enum::From;
#[repr(u8)]
#[derive(From)]
pub enum Enum {
Bar = 0b00,
Foo = 0b01,
Rest = 0b11
}
will create a from(u8) -> Enum conversion function which maps 0 -> Bar, 1 -> Foo and all other values to Rest.
lib.rs
:
Surjective mapping for conversion of enum representation to enmu. See the macro documentation and tests for example usage.
Dependencies
~2MB
~48K SLoC