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
sourceimpl 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
sourceimpl ToTokens for Scope
impl ToTokens for Scope
sourcefn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
Write self to the given TokenStream. Read more
sourcefn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Convert self directly into a TokenStream object. Read more
sourcefn into_token_stream(self) -> TokenStream
fn into_token_stream(self) -> TokenStream
Convert self directly into a TokenStream object. Read more
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Spanned for T where
T: Spanned + ?Sized,
impl<T> Spanned for T where
T: Spanned + ?Sized,
sourcefn span(&self) -> Span
fn span(&self) -> Span
Returns a Span covering the complete contents of this syntax tree
node, or Span::call_site() if this node is empty. Read more