Struct impl_tools_lib::Scope

source ·
pub struct Scope {
    pub attrs: Vec<Attribute>,
    pub vis: Visibility,
    pub ident: Ident,
    pub generics: Generics,
    pub item: ScopeItem,
    pub semi: Option<Semi>,
    pub impls: Vec<ItemImpl>,
    pub generated: Vec<TokenStream>,
}
Expand description

Contents of impl_scope!

impl_scope! input consists of one item (an enum, struct, type alias or union) followed by any number of implementations, and is parsed into this struct.

On its own, impl_scope! provides impl Self syntax, with the following expansion done within Self::expand (after application ScopeAttr rules):

  • impl Self { ... } expands to impl #impl_generics #ty_ident #ty_generics #where_clause { ... }
  • impl Self where #clause2 { ... } expands similarly, but using the combined where clause

The secondary utility of impl_scope! is to allow attribute expansion within itself via ScopeAttr rules. These rules may read the type item (which may include field initializers in the case of a struct), read accompanying implementations, and even modify them.

Fields§

§attrs: Vec<Attribute>

Outer attributes on the item

§vis: Visibility

Optional pub, etc.

§ident: Ident

Item identifier

§generics: Generics

Item generics

§item: ScopeItem

The item

§semi: Option<Semi>

Trailing semicolon (type alias and unit struct only)

§impls: Vec<ItemImpl>

Implementation items

§generated: Vec<TokenStream>

Output of ScopeAttr rules

This does not contain any content from input, only content generated from ScopeAttr rules. It is appended to output as an item (usually a syn::ImplItem), after Self::impls items.

Implementations§

Apply attribute rules

The supplied rules are applied in the order of definition, and their attributes removed from the item.

Expand impl Self

This is done automatically by Self::expand. It may be called earlier by a ScopeAttr if required. Calling multiple times is harmless.

Generate the TokenStream

This is a convenience function. It is valid to, instead, (1) call Self::expand_impl_self, then (2) use the ToTokens impl on Scope.

Trait Implementations§

Formats the value using the given formatter. Read more
Write self to the given TokenStream. Read more
Convert self directly into a TokenStream object. Read more
Convert self directly into a TokenStream object. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Returns a Span covering the complete contents of this syntax tree node, or Span::call_site() if this node is empty. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.