binja_derive 0.1.1

Derive for #[binja(BinarySerialize, BinaryParse)].
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use syn::parse_quote;

pub fn add_trait_bounds(generics: &syn::Generics, trait_path: syn::Path) -> syn::Generics {
    // Clone generics to modify
    let mut generics_with_bounds = generics.clone();
    let where_clause = generics_with_bounds.make_where_clause();

    // Add trait bounds to each type parameter
    for param in generics.type_params() {
        let ident = &param.ident;
        where_clause.predicates.push(parse_quote! {
            #ident: #trait_path
        });
    }

    generics_with_bounds
}