Enum Variants Strings

Crates.io badge Docs.rs badge

Generates conversions of enums from strings and into strings based on variant identifiers

```rust use enumvariantsstrings::EnumVariantsStrings;

[derive(Debug, PartialEq, EnumVariantsStrings)]

enum Variants { X, Y(i32), #[enumvariantsstrings_mappings("z", "zee")] Z { x: String, y: String, }, }

fn main() { asserteq!(Variants::fromstr("x"), Ok(Variants::X)); asserteq!(Variants::fromstr("y"), Ok(Variants::Y(0))); asserteq!( Variants::fromstr("z"), Ok(Variants::Z { x: String::default(), y: String::default(), }) );

assert_eq!(Variants::X.to_str(), "x");
assert_eq!(
    Variants::Z {
        x: "abc".into(),
        y: "xyz".into()
    }
    .to_str(),
    "zee"
);

} ```

Identifier mapping

By default variant identifier/names are transformed to their snake case version

This can be changed via #[enum_variants_strings_transform(transform = ...)]

```rust use enumvariantsstrings::EnumVariantsStrings;

[derive(Debug, PartialEq, EnumVariantsStrings)]

[enumvariantsstrings_transform(transform = "none")]

enum EnumA { Foo, Bar, } ```

There are several transforms