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 type is available only if Syn is built with the "derive"
or "full"
feature.
Fields
lt_token: Option<Lt>
params: Punctuated<GenericParam, Comma>
gt_token: Option<Gt>
where_clause: Option<WhereClause>
Implementations
sourceimpl Generics
impl Generics
sourcepub fn type_params(&self) -> TypeParams<'_>
pub fn type_params(&self) -> TypeParams<'_>
Returns an
Iterator<Item = &
TypeParam
>
over the type parameters in self.params
.
sourcepub fn type_params_mut(&mut self) -> TypeParamsMut<'_>
pub fn type_params_mut(&mut self) -> TypeParamsMut<'_>
Returns an
Iterator<Item = &mut
TypeParam
>
over the type parameters in self.params
.
sourcepub fn lifetimes(&self) -> Lifetimes<'_>
pub fn lifetimes(&self) -> Lifetimes<'_>
Returns an
Iterator<Item = &
LifetimeDef
>
over the lifetime parameters in self.params
.
sourcepub fn lifetimes_mut(&mut self) -> LifetimesMut<'_>
pub fn lifetimes_mut(&mut self) -> LifetimesMut<'_>
Returns an
Iterator<Item = &mut
LifetimeDef
>
over the lifetime parameters in self.params
.
sourcepub fn const_params(&self) -> ConstParams<'_>
pub fn const_params(&self) -> ConstParams<'_>
Returns an
Iterator<Item = &
ConstParam
>
over the constant parameters in self.params
.
sourcepub fn const_params_mut(&mut self) -> ConstParamsMut<'_>
pub fn const_params_mut(&mut self) -> ConstParamsMut<'_>
Returns an
Iterator<Item = &mut
ConstParam
>
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.
sourceimpl Generics
impl Generics
sourcepub fn split_for_impl(
&self
) -> (ImplGenerics<'_>, TypeGenerics<'_>, Option<&WhereClause>)
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 {
// ...
}
}
This method is available only if Syn is built with the "derive"
or
"full"
feature and the "printing"
feature.
Trait Implementations
sourceimpl ToTokens for Generics
impl ToTokens for Generics
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 Generics
impl !Send for Generics
impl !Sync for Generics
impl Unpin for Generics
impl UnwindSafe for Generics
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub 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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more