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 toimpl #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§
source§impl Scope
impl Scope
sourcepub fn apply_attrs(
&mut self,
find_rule: impl Fn(&Path) -> Option<&'static dyn ScopeAttr>
)
pub fn apply_attrs(
&mut self,
find_rule: impl Fn(&Path) -> Option<&'static dyn ScopeAttr>
)
Apply attribute rules
The supplied rules
are applied in the order of definition, and their
attributes removed from the item.
sourcepub fn expand_impl_self(&mut self)
pub fn expand_impl_self(&mut self)
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.
sourcepub fn expand(self) -> TokenStream
pub fn expand(self) -> TokenStream
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
.