#no-alloc #default #repr #u8 #derive

no-std strum-lite

Lightweight declarative macro for sets of strings

2 releases

Uses new Rust 2024

new 0.1.1 Mar 29, 2025
0.1.0 Mar 29, 2025

#342 in Parser tooling

MIT OR Apache-2.0 OR Unlicense OR WTFPL

12KB
171 lines

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 custom error type rather than using this crate's ParseError.
strum_lite::with_error! {
    #[derive(Default)]
    #[repr(u8)]
    pub enum Casing {
        Kebab = "kebab-case" | "kebab" = 1,
        #[default]
        ScreamingSnake = "SCREAMING_SNAKE" = 1 + 2,
    }
    throws
    #[derive(Clone, Copy)]
    ParseCasingError;
}

lib.rs:

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 custom error type rather than using this crate's ParseError.
strum_lite::with_error! {
    #[derive(Default)]
    #[repr(u8)]
    pub enum Casing {
        Kebab = "kebab-case" | "kebab" = 1,
        #[default]
        ScreamingSnake = "SCREAMING_SNAKE" = 1 + 2,
    }
    throws
    #[derive(Clone, Copy)]
    ParseCasingError;
}

No runtime deps