#[derive(FromToStr)]
{
// Attributes available to this derive:
#[fromtostr]
}
Expand description
Implements
AsRef<str>,
Into<String>1,
Display (therefore ToString1), FromStr,
TryFrom<String>1,
Serialize2 and Deserialize2 for enum.
use fieldless_enum_tools::FromToStr;
#[derive(FromToStr, Debug, PartialEq, Eq, Clone, Copy)]
#[fromtostr(format(style = "delimited", separator = "😎"))]
enum CoolEnum {
#[fromtostr(aliases("cool_variant_one"))]
CoolVariantOne,
#[fromtostr(rename("Very😎Cool😎Variant😎Two"))]
CoolVariantTwo
}
let cool = CoolEnum::CoolVariantOne;
assert_eq!(cool.as_ref(), "Cool😎Variant😎One");
assert_eq!("cool_variant_one".parse(), Ok(cool));
assert_eq!("Cool😎Variant😎One".parse(), Ok(cool));
let cool = CoolEnum::CoolVariantTwo;
assert_eq!("Very😎Cool😎Variant😎Two".parse(), Ok(cool));
assert_eq!("uncool variant :(".parse::<CoolEnum>(), Err(()));
// errors because we renamed it to Very😎Cool😎Variant😎Two
assert_eq!("Cool😎Variant😎Two".parse::<CoolEnum>(), Err(()));§Attributes
§Outer attributes
#[fromtostr(skip(...*))]
Skips implementing specified traits
Possible Values
Value Skips TryFromStringTryFrom<String>FromStrFromStrAsRefStrAsRef<str>IntoStringInto<String>DisplayDisplaySerializeSerializeDeserializeDeserialize
#[fromtostr(format(style = "...", separator = "..."?))]
Format variants using specified style
§Variant attributes
#[fromtostr(aliases("..."*))]
Specifies one (or more aliases) for this variant
#[fromtostr(rename("..."))] or #[fromtostr(rename(style = "...", separator = "..."?))]
Renames this variant with specified string or specified format style
§Possible Styles
Style Name Description Example Note nonekeep it as is TwoWordslowerto lowercase twowordsUPPERto uppercase TWOWORDSsnaketo snake case two_wordsalias to delimitedlowerstyle with a_separatorkebabto kebab case two-wordsalias to delimitedlowerstyle with a-separatorSCREAMING_SNAKEto screaming snake case TWO_WORDSalias to DELIMITEDUPPERwith a_separatorSCREAMING-KEBABto screaming kebab case TWO-WORDSalias it to DELIMITEDUPPERstyle with a-separatorcamelto camel case twoWordscamel_Snaketo camel snake case two_WordsPascalto pascal case TwoWordsPascal_Snaketo pascal snake case Two_WordsTrainto train case Two-Wordsdelimiteddelimits every word with separator Two{separator}Wordsneeds to specify a separator value delimitedlowerdelimits every word with separator, then to lowercase two{separator}wordsneeds to specify a separator value DELIMITEDUPPERdelimits every word with separator, then to uppercase TWO{SEPARATOR}WORDSneeds to specify a separator value