Function macro_tools::generic_params::only_names

source ·
pub fn only_names(generics: &Generics) -> Generics
Expand description

Extracts parameter names from the given Generics, dropping bounds, defaults, and the where clause.

This function simplifies the generics to include only the names of the type parameters, lifetimes, and const parameters, without any of their associated bounds or default values. The resulting Generics will have an empty where clause.

§Arguments

  • generics - The Generics instance from which to extract parameter names.

§Returns

Returns a new Generics instance containing only the names of the parameters.

§Examples


let mut generics : syn::Generics = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > };
generics.where_clause = parse_quote!{ where T: core::fmt::Debug };
// let generics : Generics = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > where T: core::fmt::Debug };
let simplified_generics = macro_tools::generic_params::only_names( &generics );

assert_eq!( simplified_generics.params.len(), 4 ); // Contains T, U, 'a, and N
assert!( simplified_generics.where_clause.is_none() ); // Where clause is removed