AttributeExt

Trait AttributeExt 

Source
pub trait AttributeExt {
    // Required methods
    fn from_meta<M>(meta: M) -> Self
       where M: IntoAttribute;
    fn parse_meta(&self) -> Result<Meta1>;
    fn try_meta_mut<F, R>(&mut self, f: F) -> Result<R>
       where F: FnOnce(&mut Meta1) -> Result<R>;
    fn promoted_list(&self) -> Result<MetaList1>;
    fn try_promoted_list_mut<F, R>(&mut self, paren: Paren, f: F) -> Result<R>
       where F: FnOnce(&mut MetaList1) -> Result<R>;
}
Expand description

Extension for syn::Attribute

Required Methods§

Source

fn from_meta<M>(meta: M) -> Self
where M: IntoAttribute,

Constructs and returns a new syn::Attribute from syn::Meta

Source

fn parse_meta(&self) -> Result<Meta1>

Parses the content of the attribute, consisting of the path and tokens, as a Meta if possible.

Source

fn try_meta_mut<F, R>(&mut self, f: F) -> Result<R>
where F: FnOnce(&mut Meta1) -> Result<R>,

Takes a closure and calls it with parsed meta. After call, applys back the manipulated syn::Meta.

  1. Try syn::Attribute::parse_meta; return if Err
  2. Run f
  3. Apply back the manipulated syn::Meta by f.
  4. Return the result of f.

Note: Even f returns Err, meta will be made into self.

Source

fn promoted_list(&self) -> Result<MetaList1>

Returns a fake promoted list value of syn::MetaList.

If syn::Meta::List, return inner syn::MetaList. If syn::Meta::Path, return a fake syn::MetaList with default paren and empty nested. Otherwise return Err

Source

fn try_promoted_list_mut<F, R>(&mut self, paren: Paren, f: F) -> Result<R>
where F: FnOnce(&mut MetaList1) -> Result<R>,

Takes a closure and calls it with promoted list of parsed meta. After call, applys back the manipulated syn::MetaList.

  1. Try syn::Attribute::parse_meta; return if Err
  2. Promote to syn::Meta::List if syn::Meta::Path
  3. Run f to inner syn::MetaList
  4. Apply back the manipulated syn::Meta by f.
  5. Return the result of f.

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 AttributeExt for Attribute

Source§

fn from_meta<M>(meta: M) -> Self
where M: IntoAttribute,

Source§

fn parse_meta(&self) -> Result<Meta1>

Source§

fn try_meta_mut<F, R>(&mut self, f: F) -> Result<R>
where F: FnOnce(&mut Meta1) -> Result<R>,

Source§

fn promoted_list(&self) -> Result<MetaList1>

Source§

fn try_promoted_list_mut<F, R>(&mut self, paren: Paren, f: F) -> Result<R>
where F: FnOnce(&mut MetaList1) -> Result<R>,

Implementors§