impl_trait_for_tuples/
utils.rs

1//! Provides common utils function shared between full and semi-automatic.
2
3use proc_macro2::TokenStream;
4
5use syn::{parse_quote, Generics, Ident};
6
7use quote::quote;
8
9/// Add the given tuple elements as generics with the given `bounds` to `generics`.
10pub fn add_tuple_element_generics(
11    tuple_elements: &[Ident],
12    bounds: Option<TokenStream>,
13    generics: &mut Generics,
14) {
15    let bound = bounds.map(|b| quote!(: #b)).unwrap_or_else(|| quote!());
16
17    tuple_elements.iter().for_each(|tuple_element| {
18        generics.params.push(parse_quote!(#tuple_element #bound));
19    });
20}