strum
strum copied to clipboard
Implement From<&str> instead of FromStr for enums with lifetimes
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),
}
FromStr still has its use when dealing with generic code, so I would not advocate for "instead of". (Btw that would be TryFrom).