strum icon indicating copy to clipboard operation
strum copied to clipboard

Implement From<&str> instead of FromStr for enums with lifetimes

Open leo60228 opened this issue 6 years ago • 1 comments
trafficstars

FromStr doesn't support lifetimes, and I'd like the following to be possible:

#[derive(Debug, PartialEq, Eq, Clone, Copy, strum_macros::AsRefStr, strum_macros::EnumString)]
pub enum ChunkType<'a> {
    #[strum(to_string = "nMC")]
    MChat,
    #[strum(to_string = "nM")]
    MPlayer,
    #[strum(to_string = "nMR")]
    MRequest,
    #[strum(to_string = "nM?")]
    MServerInfo,
    #[strum(to_string = "nU")]
    UUpdate,
    #[strum(to_string = "\r\n")]
    Eof,
    #[strum(to_string = "nH")]
    HHead,
    #[strum(default = "true")]
    Unknown(&'a str),
}

leo60228 avatar Sep 12 '19 15:09 leo60228

FromStr still has its use when dealing with generic code, so I would not advocate for "instead of". (Btw that would be TryFrom).

Ten0 avatar Apr 20 '20 09:04 Ten0