Trait synthez::ParseAttrs
source · pub trait ParseAttrs: Default + Parse {
// Required method
fn try_merge(self, another: Self) -> Result<Self, Error>;
// Provided methods
fn validate(&self, _: &str, _: Span) -> Result<(), Error> { ... }
fn fallback(&mut self, _: &[Attribute]) -> Result<(), Error> { ... }
fn parse_attrs<T>(name: &str, item: &T) -> Result<Self, Error>
where T: Attrs,
&'a T: for<'a> IntoSpan { ... }
}
Expand description
Parse
ing of syn::Attribute
s into a custom defined struct.
Required Methods§
Provided Methods§
sourcefn validate(&self, _: &str, _: Span) -> Result<(), Error>
fn validate(&self, _: &str, _: Span) -> Result<(), Error>
Validates these parsed attributes to meet additional invariants, if required.
The provided string contains name of the parsed syn::Attribute
, and
the provided Span
refers to the item this syn::Attribute
is
applied to. Use them to make reported errors well descriptive.
Errors
If validation fails.
sourcefn fallback(&mut self, _: &[Attribute]) -> Result<(), Error>
fn fallback(&mut self, _: &[Attribute]) -> Result<(), Error>
Falls back to another values from syn::Attribute
s, if required.
Errors
If retrieving fallback values fails.
sourcefn parse_attrs<T>(name: &str, item: &T) -> Result<Self, Error>where
T: Attrs,
&'a T: for<'a> IntoSpan,
fn parse_attrs<T>(name: &str, item: &T) -> Result<Self, Error>where T: Attrs, &'a T: for<'a> IntoSpan,
Parses this structure from the syn::Attribute
s with the given name
and contained in the given item
.
If multiple syn::Attribute
s occur with the same name
then they all
are parsed separately and then Attrs::try_merge
d.
If none syn::Attribute
s occur with the given name
then Default
value is returned, modulo Attrs::validate
.
Errors
- If
Parse
ing of thisAttrs
fails. - If either
Attrs::try_merge()
,Attrs::validate()
orAttrs::fallback()
fails.