Struct syn::Generics

source ·
pub struct Generics {
    pub lt_token: Option<Lt>,
    pub params: Punctuated<GenericParam, Comma>,
    pub gt_token: Option<Gt>,
    pub where_clause: Option<WhereClause>,
}
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

source

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

Returns an Iterator<Item = &LifetimeParam> over the lifetime parameters in self.params.

source

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

Returns an Iterator<Item = &mut LifetimeParam> over the lifetime parameters in self.params.

source

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

Returns an Iterator<Item = &TypeParam> over the type parameters in self.params.

source

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

Returns an Iterator<Item = &mut TypeParam> over the type parameters in self.params.

source

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

Returns an Iterator<Item = &ConstParam> over the constant parameters in self.params.

source

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

Returns an Iterator<Item = &mut ConstParam> over the constant parameters in self.params.

source

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

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

source§

impl Generics

source

pub 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.

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 Clone for Generics

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Generics

source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Generics

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Hash for Generics

source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Parse for Generics

source§

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

source§

impl PartialEq for Generics

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl ToTokens for Generics

source§

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

Write self to the given TokenStream. Read more
source§

fn to_token_stream(&self) -> TokenStream

Convert self directly into a TokenStream object. Read more
source§

fn into_token_stream(self) -> TokenStream
where Self: Sized,

Convert self directly into a TokenStream object. Read more
source§

impl Eq for Generics

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

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

source§

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.
source§

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

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

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

Performs the conversion.