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: VisibilityOptional pub, etc.
ident: IdentItem identifier
generics: GenericsItem generics
item: ScopeItemThe 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.
Trait Implementations§
source§impl ToTokens for Scope
impl ToTokens for Scope
source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere Self: Sized,
Auto Trait Implementations§
impl RefUnwindSafe for Scope
impl !Send for Scope
impl !Sync for Scope
impl Unpin for Scope
impl UnwindSafe for Scope
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Spanned for Twhere
T: Spanned + ?Sized,
impl<T> Spanned for Twhere T: Spanned + ?Sized,
source§fn span(&self) -> Span
fn span(&self) -> Span
Span covering the complete contents of this syntax tree
node, or Span::call_site() if this node is empty.