pub struct GenericsWithWhere {
    pub generics: Generics,
}
Expand description

A GenericsWithWhere struct to handle the parsing of Rust generics with an explicit where clause.

This wrapper addresses the limitation in the syn crate where parsing Generics directly from a ParseStream does not automatically handle associated where clauses. By integrating where clause parsing into the GenericsWithWhere, this struct provides a seamless way to capture both the generics and their constraints in scenarios where the where clause is crucial for type constraints and bounds in Rust macros and code generation.

Usage:

let parsed_generics : macro_tools::GenericsWithWhere
= syn::parse_str( "< T : Clone, U : Default = Default1 > where T : Default" ).unwrap();
assert!( parsed_generics.generics.params.len() == 2 );
assert!( parsed_generics.generics.where_clause.is_some() );

Fields§

§generics: Generics

Syn’s generics parameters.

Implementations§

source§

impl GenericsWithWhere

source

pub fn unwrap(self) -> Generics

Unwraps the GenericsWithWhere to retrieve the inner syn::Generics.

source

pub fn parse_from_str(s: &str) -> Result<GenericsWithWhere>

Parses a string to a GenericsWithWhere, specifically designed to handle generics syntax with where clauses effectively.

Trait Implementations§

source§

impl Debug for GenericsWithWhere

source§

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

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

impl From<Generics> for GenericsWithWhere

source§

fn from(generics: Generics) -> Self

Converts to this type from the input type.
source§

impl From<GenericsWithWhere> for Generics

source§

fn from(g: GenericsWithWhere) -> Self

Converts to this type from the input type.
source§

impl Parse for GenericsWithWhere

source§

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

source§

impl ToTokens for GenericsWithWhere

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

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<S> AssignWithType for S

source§

fn assign_with_type<T, IntoT>(&mut self, component: IntoT)
where IntoT: Into<T>, S: Assign<T, IntoT>,

Sets the value of a component by its type. 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, 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.