Trait from_attr::FromAttr

source ·
pub trait FromAttr: Sized {
    type Parser: ParseMeta + Default;

    // Required method
    fn from_parser(parser: Self::Parser, spans: &[Span]) -> Result<Self>;

    // Provided methods
    fn from_meta_list(list: &MetaList) -> Result<Option<Self>>
       where Self: AttributeIdent { ... }
    fn from_attributes(
        attrs: &[Attribute]
    ) -> Result<Option<AttrsValue<&Attribute, Self>>, AttrsValue<&Attribute, Error>>
       where Self: AttributeIdent { ... }
    fn remove_attributes(
        attrs: &mut Vec<Attribute>
    ) -> Result<Option<AttrsValue<Attribute, Self>>, AttrsValue<Attribute, Error>>
       where Self: AttributeIdent { ... }
    fn from_tokens(tokens: TokenStream) -> Result<Self> { ... }
}
Expand description

Used for conversion from Attributes, MetaList, TokenStream to values.

Instead of converting directly from Attributes, MetaList, TokenStream to values, we need to use the helper type that implements ParseMeta and Default to convert to this type first, and then convert to the value we really need.

Required Associated Types§

source

type Parser: ParseMeta + Default

The helper type that implements ParseMeta and Default.

Required Methods§

source

fn from_parser(parser: Self::Parser, spans: &[Span]) -> Result<Self>

Convert from Parser to values.

Provided Methods§

source

fn from_meta_list(list: &MetaList) -> Result<Option<Self>>
where Self: AttributeIdent,

Convert from MetaList to values.

source

fn from_attributes( attrs: &[Attribute] ) -> Result<Option<AttrsValue<&Attribute, Self>>, AttrsValue<&Attribute, Error>>
where Self: AttributeIdent,

Convert from Attributes to values.

Does not remove Attributes and is generally used to parse attributes of derive macros.

source

fn remove_attributes( attrs: &mut Vec<Attribute> ) -> Result<Option<AttrsValue<Attribute, Self>>, AttrsValue<Attribute, Error>>
where Self: AttributeIdent,

Convert from Attributes to values.

Does remove Attributes and is generally used to parse attributes of attribute macros.

source

fn from_tokens(tokens: TokenStream) -> Result<Self>

Convert from TokenStream to values.

Generally used for parsing TokenStream for attribute macros.

Object Safety§

This trait is not object safe.

Implementors§