Crates.io | finte-derive |
lib.rs | finte-derive |
version | 0.2.0 |
source | src |
created_at | 2021-06-29 16:46:20.661785 |
updated_at | 2021-07-23 01:09:25.688279 |
description | #[derive(IntEnum)] support for finte |
homepage | |
repository | https://github.com/hismito/finte |
max_upload_size | |
id | 416232 |
size | 9,544 |
Finte is a proc-macro crate to auto generate conversion code between integer and Rust enum
#[derive(finte::IntEnum)]
#[repr(u16)]
pub enum RustEdition {
Prev = 2015,
Now = 2018,
Next = 2021,
}
// the above generates
impl finte::IntEnum for RustEdition {
type Int = u16;
fn try_from_int(value: Self::Int) -> Option<Self> {
match value {
2015 => Some(Self::Prev),
2018 => Some(Self::Now),
2021 => Some(Self::Next),
_ => None,
}
}
fn int_value(&self) -> Self::Int {
match self {
Self::Prev => 2015,
Self::Now => 2018,
Self::Next => 2021,
}
}
}