strum icon indicating copy to clipboard operation
strum copied to clipboard

Useful changes to `EnumString`

Open AlexSherbinin opened this issue 7 months ago • 0 comments

  1. Added support for enums that consuming strings they have parsed from.
  2. Changed behaviour to derive From trait instead of TryFrom when default variant is defined(TryFrom'll be defined automatically with Infallible as error type).

[!NOTE]
Maybe a breaking change, because error type of TryFrom trait is changed from ParseError to Infallible. Enums that consuming strings was leading to compiler error, so there's no breaking change in that part

Changes usage example:

#[derive(Debug, Eq, PartialEq, EnumString)]
#[strum(serialize_all = "UPPERCASE")]
enum HttpMethod<'a> {
    Get,
    Post,
    #[strum(default)]
    Unrecognized(&'a str),
}

AlexSherbinin avatar Jul 18 '24 18:07 AlexSherbinin