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§
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.