Struct Generics

pub struct Generics { pub lt_token: Option<Lt>, pub params: Punctuated<GenericParam, Comma>, pub gt_token: Option<Gt>, pub where_clause: Option<WhereClause> }

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

impl Generics

fn lifetimes(&self) -> Lifetimes<'_>

Iterator over the lifetime parameters in self.params.

fn lifetimes_mut(&mut self) -> LifetimesMut<'_>

Iterator over the lifetime parameters in self.params.

fn type_params(&self) -> TypeParams<'_>

Iterator over the type parameters in self.params.

fn type_params_mut(&mut self) -> TypeParamsMut<'_>

Iterator over the type parameters in self.params.

fn const_params(&self) -> ConstParams<'_>

Iterator over the constant parameters in self.params.

fn const_params_mut(&mut self) -> ConstParamsMut<'_>

Iterator over the constant parameters in self.params.

fn make_where_clause(&mut self) -> &mut WhereClause

Initializes an empty where-clause if there is not one present already.

fn split_for_impl(&self) -> (ImplGenerics<'_>, TypeGenerics<'_>, Option<&WhereClause>)

Split a type's generics into the pieces required for impl'ing a trait for that type.

# use proc_macro2::{Span, Ident};
# use quote::quote;
#
# let generics: syn::Generics = Default::default();
# let name = Ident::new("MyType", Span::call_site());
#
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
quote! {
    impl #impl_generics MyTrait for #name #ty_generics #where_clause {
        // ...
    }
}
# ;

Trait Implementations

impl Clone for Generics

fn clone(&self) -> Self

impl Default for Generics

fn default() -> Self

impl Parse for Generics

fn parse(input: ParseStream<'_>) -> Result<Self>

impl ToTokens for Generics

fn to_tokens(&self, tokens: &mut TokenStream)

Auto Trait Implementations

impl !Send for Generics

impl !Sync for Generics

impl Freeze for Generics

impl RefUnwindSafe for Generics

impl Unpin for Generics

impl UnsafeUnpin for Generics

impl UnwindSafe for Generics

Blanket Implementations

impl<T> Any for Generics where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Generics where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Generics where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Generics where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Generics

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Spanned for Generics where T: Spanned + ?Sized,

fn span(&self) -> Span

impl<T> ToOwned for Generics where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for Generics where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Generics where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Generics where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>