use crate :: *;
#[ must_use ]
pub fn merge_params_ordered(
param_lists: &[ &syn ::punctuated ::Punctuated< syn ::GenericParam, syn ::token ::Comma >],
) -> syn ::punctuated ::Punctuated< syn ::GenericParam, syn ::token ::Comma > {
let mut lifetimes = Vec ::new();
let mut types = Vec ::new();
let mut consts = Vec ::new();
for params in param_lists
{
for param in *params
{
match param
{
syn ::GenericParam ::Lifetime(lt) => lifetimes.push(syn ::GenericParam ::Lifetime(lt.clone())),
syn ::GenericParam ::Type(ty) => types.push(syn ::GenericParam ::Type(ty.clone())),
syn ::GenericParam ::Const(ct) => consts.push(syn ::GenericParam ::Const(ct.clone())),
}
}
}
let mut result = syn ::punctuated ::Punctuated ::new();
let all_params: Vec< _ > = lifetimes.into_iter()
.chain(types)
.chain(consts)
.collect();
for (idx, param) in all_params.iter().enumerate()
{
result.push_value(param.clone());
if idx < all_params.len() - 1
{
result.push_punct(syn ::token ::Comma ::default());
}
}
result
}
#[ must_use ]
pub fn params_with_additional(
base: &syn ::punctuated ::Punctuated< syn ::GenericParam, syn ::token ::Comma >,
additional: &[ syn ::GenericParam],
) -> syn ::punctuated ::Punctuated< syn ::GenericParam, syn ::token ::Comma > {
let mut result = base.clone();
while result.trailing_punct()
{
result.pop_punct();
}
for param in additional
{
if !result.is_empty()
{
result.push_punct(syn ::token ::Comma ::default());
}
result.push_value(param.clone());
}
result
}
#[ must_use ]
pub fn params_from_components(
lifetimes: &[ syn ::LifetimeParam],
types: &[ syn ::TypeParam],
consts: &[ syn ::ConstParam],
) -> syn ::punctuated ::Punctuated< syn ::GenericParam, syn ::token ::Comma > {
let mut result = syn ::punctuated ::Punctuated ::new();
let all_params: Vec< syn ::GenericParam > = lifetimes.iter()
.map(|lt| syn ::GenericParam ::Lifetime(lt.clone()))
.chain(types.iter().map(|ty| syn ::GenericParam ::Type(ty.clone())))
.chain(consts.iter().map(|ct| syn ::GenericParam ::Const(ct.clone())))
.collect();
for (idx, param) in all_params.iter().enumerate()
{
result.push_value(param.clone());
if idx < all_params.len() - 1
{
result.push_punct(syn ::token ::Comma ::default());
}
}
result
}