known_attribute

Function known_attribute 

Source
pub fn known_attribute<T>(identity: &Ident) -> Result<T, Error>
Expand description

Parses one bare word like “rename” for any iterable enum, and that’s it

Won’t parse an equal sign or anything else. Emits all known keys for debugging help when an unknown string is passed in.

Can be used to derive syn::parse::Parse for the discriminant or the enum directly.

assert_eq!(KnownAttribute::ignore, syn::parse_str("ignore").unwrap());
assert_eq!(KnownAttribute::rename, syn::parse_str("rename").unwrap());
assert!(syn::parse_str::<KnownAttribute>("unknown").is_err());

impl syn::parse::Parse for KnownAttribute {
    fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
        let ident = input.parse::<syn::Ident>()?;
        proc_micro::known_attribute(&ident)
    }
}

#[derive(strum::EnumDiscriminants, Debug, PartialEq)]
#[strum_discriminants(
    name(KnownAttribute),
    derive(strum::EnumIter, strum::Display, strum::EnumString, Hash)
)]
enum ParseAttribute {
    #[allow(non_camel_case_types)]
    rename(String),
    #[allow(non_camel_case_types)]
    ignore,
}