pub struct Generics {
pub lt_token: Option<Lt>,
pub params: Punctuated<GenericParam, Comma>,
pub gt_token: Option<Gt>,
pub where_clause: Option<WhereClause>,
}
full
or derive
only.Expand description
Lifetimes and type parameters attached to a declaration of a function, enum, trait, etc.
This struct represents two distinct optional syntactic elements, generic parameters and where clause. In some locations of the grammar, there may be other tokens in between these two things.
Fields§
§lt_token: Option<Lt>
§params: Punctuated<GenericParam, Comma>
§gt_token: Option<Gt>
§where_clause: Option<WhereClause>
Implementations§
Source§impl Generics
impl Generics
Sourcepub fn lifetimes(&self) -> impl Iterator<Item = &LifetimeParam>
pub fn lifetimes(&self) -> impl Iterator<Item = &LifetimeParam>
Iterator over the lifetime parameters in self.params
.
Sourcepub fn lifetimes_mut(&mut self) -> impl Iterator<Item = &mut LifetimeParam>
pub fn lifetimes_mut(&mut self) -> impl Iterator<Item = &mut LifetimeParam>
Iterator over the lifetime parameters in self.params
.
Sourcepub fn type_params(&self) -> impl Iterator<Item = &TypeParam>
pub fn type_params(&self) -> impl Iterator<Item = &TypeParam>
Iterator over the type parameters in self.params
.
Sourcepub fn type_params_mut(&mut self) -> impl Iterator<Item = &mut TypeParam>
pub fn type_params_mut(&mut self) -> impl Iterator<Item = &mut TypeParam>
Iterator over the type parameters in self.params
.
Sourcepub fn const_params(&self) -> impl Iterator<Item = &ConstParam>
pub fn const_params(&self) -> impl Iterator<Item = &ConstParam>
Iterator over the constant parameters in self.params
.
Sourcepub fn const_params_mut(&mut self) -> impl Iterator<Item = &mut ConstParam>
pub fn const_params_mut(&mut self) -> impl Iterator<Item = &mut ConstParam>
Iterator over the constant parameters in self.params
.
Sourcepub fn make_where_clause(&mut self) -> &mut WhereClause
pub fn make_where_clause(&mut self) -> &mut WhereClause
Initializes an empty where
-clause if there is not one present already.
Sourcepub fn split_for_impl(
&self,
) -> (ImplGenerics<'_>, TypeGenerics<'_>, Option<&WhereClause>)
Available on crate feature printing
only.
pub fn split_for_impl( &self, ) -> (ImplGenerics<'_>, TypeGenerics<'_>, Option<&WhereClause>)
printing
only.Split a type’s generics into the pieces required for impl’ing a trait for that type.
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
quote! {
impl #impl_generics MyTrait for #name #ty_generics #where_clause {
// ...
}
}
Trait Implementations§
Source§impl Parse for Generics
Available on crate feature parsing
only.
impl Parse for Generics
parsing
only.fn parse(input: ParseStream<'_>) -> Result<Self>
Source§impl ToTokens for Generics
Available on crate feature printing
only.
impl ToTokens for Generics
printing
only.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,
impl Eq for Generics
extra-traits
only.Auto Trait Implementations§
impl Freeze for Generics
impl RefUnwindSafe for Generics
impl !Send for Generics
impl !Sync for Generics
impl Unpin for Generics
impl UnwindSafe for Generics
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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
parsing
and printing
only.Span
covering the complete contents of this syntax tree
node, or Span::call_site()
if this node is empty.Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 88 bytes