strum-lite 0.2.1

Lightweight declarative macro for sets of strings.
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented2 out of 3 items with examples
  • Size
  • Source code size: 12.04 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 189.96 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 6s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • aatifsyed/strum-lite
    9 2 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • aatifsyed

Lightweight declarative macro for sets of strings.

strum_lite::strum! {
    pub enum Casing {
        Kebab = "kebab-case",
        ScreamingSnake = "SCREAMING_SNAKE",
    }
}

Features

  • Implements FromStr and Display.
  • Attributes (docs, #[derive(..)]s) are passed through to the definition and variants.
  • Aliases are supported.
  • Custom enum discriminants are passed through.
  • Generated code is #![no_std].
  • The generated FromStr::Err provides a helpful error message.
  • You may ask for a const of all the variants.
  • You may ask for a custom zero-sized error type rather than using this crate's [ParseError].
strum_lite::strum! {
    #[derive(Debug, PartialEq, Default)]
    #[repr(u8)]
    pub enum Casing {
        Kebab = "kebab-case" | "kebab" = 1,
        #[default]
        ScreamingSnake = "SCREAMING_SNAKE" = 1 + 2,
    }
    pub const VARIANTS;
    throws
    #[derive(Clone, Copy)]
    ParseCasingError;
}

assert_eq!(Casing::VARIANTS, [Casing::Kebab, Casing::ScreamingSnake]);
assert_eq!("kebab".parse::<Casing>().unwrap(), Casing::Kebab);