finte-derive 0.2.0

#[derive(IntEnum)] support for finte
Documentation
  • Coverage
  • 0%
    0 out of 2 items documented0 out of 2 items with examples
  • Size
  • Source code size: 9.18 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 38.02 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • hismito/finte
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hismito

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,
        }
    }
}