Struct macro_tools::generic_params::GenericsWithWhere
source · 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
impl GenericsWithWhere
sourcepub fn unwrap(self) -> Generics
pub fn unwrap(self) -> Generics
Unwraps the GenericsWithWhere
to retrieve the inner syn::Generics
.
sourcepub fn parse_from_str(s: &str) -> Result<GenericsWithWhere>
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
impl Debug for GenericsWithWhere
source§impl From<Generics> for GenericsWithWhere
impl From<Generics> for GenericsWithWhere
source§impl From<GenericsWithWhere> for Generics
impl From<GenericsWithWhere> for Generics
source§fn from(g: GenericsWithWhere) -> Self
fn from(g: GenericsWithWhere) -> Self
Converts to this type from the input type.
source§impl Parse for GenericsWithWhere
impl Parse for GenericsWithWhere
fn parse(input: ParseStream<'_>) -> Result<Self>
source§impl ToTokens for GenericsWithWhere
impl ToTokens for GenericsWithWhere
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,
Auto Trait Implementations§
impl Freeze for GenericsWithWhere
impl RefUnwindSafe for GenericsWithWhere
impl !Send for GenericsWithWhere
impl !Sync for GenericsWithWhere
impl Unpin for GenericsWithWhere
impl UnwindSafe for GenericsWithWhere
Blanket Implementations§
source§impl<S> AssignWithType for S
impl<S> AssignWithType for S
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
Mutably borrows from an owned value. Read more
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
Returns a
Span
covering the complete contents of this syntax tree
node, or Span::call_site()
if this node is empty.