Crate literal_enum
source ·Expand description
literal-enum
This macro can automatically implement the TryFromliteral
must be only one type
Usage Example
use literal_enum::LiteralEnum;
#[derive(LiteralEnum)]
enum Command {
/// increment pointer
#[lit = b'>']
IncrementPointer, // >
/// decrement pointer
#[lit = b'<']
DecrementPointer, // <
}
let b = b'>';
let cmd = Command::try_from(b).unwrap();
assert!(matches!(cmd, Command::IncrementPointer));
let b: u8 = cmd.into();
assert_eq!(b, b'>');
Derive Macros
- auto implement the TryFrom
trait and Into trait where the literal
must be only one type