5 releases
0.2.0 | Jul 23, 2021 |
---|---|
0.1.3 | Jul 1, 2021 |
0.1.2 | Jun 29, 2021 |
0.1.1 | Jun 29, 2021 |
0.1.0 | Jun 29, 2021 |
#60 in #auto-generate
Used in finte
10KB
211 lines
Finte
Finte is a proc-macro crate to auto generate conversion code between integer and Rust enum
Example
#[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,
}
}
}