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 !Send for Scope
impl !Sync for Scope
impl Freeze for Scope
impl RefUnwindSafe for Scope
impl Unpin for Scope
impl UnsafeUnpin 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.