Function macro_tools::generics::protected::merge
source · pub fn merge(a: &Generics, b: &Generics) -> Generics
Expand description
Merges two syn::Generics
instances into a new one.
This function takes two references to syn::Generics
and combines their
type parameters and where clauses into a new syn::Generics
instance. If
both instances have where clauses, the predicates of these clauses are merged
into a single where clause.
§Arguments
a
- A reference to the firstsyn::Generics
instance.b
- A reference to the secondsyn::Generics
instance.
§Returns
Returns a new syn::Generics
instance containing the merged type parameters
and where clauses from a
and b
.
§Examples
§use syn::{Generics, parse_quote};
let mut generics_a : syn::Generics = parse_quote!{ < T : Clone, U : Default > }; generics_a.where_clause = parse_quote!{ where T : Default }; let mut generics_b : syn::Generics = parse_quote!{ < V : std::fmt::Debug > }; generics_b.where_clause = parse_quote!{ where V : Sized }; let got = generics::merge( &generics_a, &generics_b );
let mut exp : syn::Generics = parse_quote! { < T : Clone, U : Default, V : std::fmt::Debug > }; exp.where_clause = parse_quote! { where T : Default, V : Sized };
assert_eq!( got, exp );