1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
mod structs;
mod variants;

#[proc_macro_derive(Marshal)]
pub fn derive_marshal(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let ast: syn::DeriveInput = syn::parse(input).unwrap();

    match ast.data {
        syn::Data::Struct(data) => {
            structs::make_struct_marshal_impl(&ast.ident, &ast.generics, &data.fields).into()
        }
        syn::Data::Enum(data) => {
            variants::make_variant_marshal_impl(&ast.ident, &ast.generics, &data.variants).into()
        }
        _ => unimplemented!("Nothing but structs can be derived on right now"),
    }
}
#[proc_macro_derive(Unmarshal)]
pub fn derive_unmarshal(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let ast: syn::DeriveInput = syn::parse(input).unwrap();

    match ast.data {
        syn::Data::Struct(data) => {
            structs::make_struct_unmarshal_impl(&ast.ident, &ast.generics, &data.fields).into()
        }
        syn::Data::Enum(data) => {
            variants::make_variant_unmarshal_impl(&ast.ident, &ast.generics, &data.variants).into()
        }
        _ => unimplemented!("Nothing but structs can be derived on right now"),
    }
}
#[proc_macro_derive(Signature)]
pub fn derive_signature(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let ast: syn::DeriveInput = syn::parse(input).unwrap();

    match ast.data {
        syn::Data::Struct(data) => {
            structs::make_struct_signature_impl(&ast.ident, &ast.generics, &data.fields).into()
        }
        syn::Data::Enum(_data) => {
            variants::make_variant_signature_imp(&ast.ident, &ast.generics).into()
        }
        _ => unimplemented!("Nothing but structs can be derived on right now"),
    }
}