Function macro_tools::exposed::generic_params::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 first syn::Generics instance.
  • b - A reference to the second syn::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 : core::fmt::Debug > }; generics_b.where_clause = parse_quote!{ where V : Sized }; let got = generic_params::merge( &generics_a, &generics_b );

let mut exp : syn::Generics = parse_quote! { < T : Clone, U : Default, V : core::fmt::Debug > }; exp.where_clause = parse_quote! { where T : Default, V : Sized };

assert_eq!( got, exp );