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 Attribute
s, MetaList
, TokenStream
to values.
Instead of converting directly from Attribute
s, 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§
Required Methods§
Provided Methods§
sourcefn from_meta_list(list: &MetaList) -> Result<Option<Self>>where
Self: AttributeIdent,
fn from_meta_list(list: &MetaList) -> Result<Option<Self>>where
Self: AttributeIdent,
Convert from MetaList
to values.
sourcefn from_attributes(
attrs: &[Attribute]
) -> Result<Option<AttrsValue<&Attribute, Self>>, AttrsValue<&Attribute, Error>>where
Self: AttributeIdent,
fn from_attributes(
attrs: &[Attribute]
) -> Result<Option<AttrsValue<&Attribute, Self>>, AttrsValue<&Attribute, Error>>where
Self: AttributeIdent,
sourcefn remove_attributes(
attrs: &mut Vec<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,
sourcefn from_tokens(tokens: TokenStream) -> Result<Self>
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.