Function macro_tools::exposed::generic_args::merge
source · pub fn merge(
a: &AngleBracketedGenericArguments,
b: &AngleBracketedGenericArguments,
) -> AngleBracketedGenericArguments
Expand description
Merges two syn::AngleBracketedGenericArguments
instances into a new one,
prioritizing lifetime parameters before other types of generic arguments.
This function takes two references to syn::AngleBracketedGenericArguments
and
categorizes their arguments into lifetimes and other types. It then combines
them such that all lifetimes from both instances precede any other arguments in the
resulting syn::AngleBracketedGenericArguments
instance. This is particularly useful
for ensuring that the merged generics conform to typical Rust syntax requirements where
lifetimes are declared before other generic parameters.
§Arguments
a
- A reference to the firstsyn::AngleBracketedGenericArguments
instance, containing one or more generic arguments.b
- A reference to the secondsyn::AngleBracketedGenericArguments
instance, containing one or more generic arguments.
§Returns
Returns a new syn::AngleBracketedGenericArguments
instance containing the merged
arguments from both a
and b
, with lifetimes appearing first.
§Examples
use macro_tools::{
generic_args,
syn::{parse_quote, AngleBracketedGenericArguments},
};
let a : AngleBracketedGenericArguments = parse_quote! { <'a, T: Clone, U: Default> };
let b : AngleBracketedGenericArguments = parse_quote! { <'b, V: core::fmt::Debug> };
let merged = generic_args::merge(&a, &b);
let expected: AngleBracketedGenericArguments = parse_quote! { <'a, 'b, T: Clone, U: Default, V: core::fmt::Debug> };
assert_eq!(merged, expected);
This example demonstrates how lifetimes 'a
and 'b
are placed before other generic parameters
like T
, U
, and V
in the merged result, adhering to the expected syntax order in Rust generics.