Trait ParseAttrs

Source
pub trait ParseAttrs: Default + Parse {
    // Required method
    fn try_merge(self, another: Self) -> Result<Self>;

    // Provided methods
    fn validate(&self, _: &str, _: Span) -> Result<()> { ... }
    fn fallback(&mut self, _: &[Attribute]) -> Result<()> { ... }
    fn parse_attrs<T>(name: &str, item: &T) -> Result<Self>
       where T: Attrs,
             for<'a> &'a T: IntoSpan { ... }
}
Expand description

Parseing of syn::Attributes into a custom defined struct.

Required Methods§

Source

fn try_merge(self, another: Self) -> Result<Self>

Tries to merge two sets of parsed attributes into a single one, reporting about duplicates, if any.

§Errors

If merging cannot be performed.

Provided Methods§

Source

fn validate(&self, _: &str, _: Span) -> Result<()>

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.

Source

fn fallback(&mut self, _: &[Attribute]) -> Result<()>

Falls back to another values from syn::Attributes, if required.

§Errors

If retrieving fallback values fails.

Source

fn parse_attrs<T>(name: &str, item: &T) -> Result<Self>
where T: Attrs, for<'a> &'a T: IntoSpan,

Parses this structure from the syn::Attributes with the given name and contained in the given item.

If multiple syn::Attributes occur with the same name then they all are parsed separately and then Attrs::try_merged.

If none syn::Attributes occur with the given name then Default value is returned, modulo Attrs::validate.

§Errors

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.

Implementations on Foreign Types§

Source§

impl<V: Attrs + Default + Parse> Attrs for Box<V>

Source§

fn try_merge(self, another: Self) -> Result<Self>

Source§

fn validate(&self, attr_name: &str, item_span: Span) -> Result<()>

Source§

fn fallback(&mut self, attrs: &[Attribute]) -> Result<()>

Source§

fn parse_attrs<T>(name: &str, item: &T) -> Result<Self>
where T: Attrs, for<'a> &'a T: IntoSpan,

Implementors§