1use proc_macro::TokenStream;
2use syn::{Data, DeriveInput};
3
4mod attr;
5mod common;
6mod product;
7mod sum;
8mod ty;
9
10use attr::get_my_attributes;
11use product::derive_struct;
12use sum::derive_enum;
13
14#[proc_macro_derive(CborRepr, attributes(cborrepr))]
15pub fn derive_cbor_repr(input: TokenStream) -> TokenStream {
16 let ast = syn::parse_macro_input!(input as DeriveInput);
18
19 let has_generics = ast.generics.params.len() > 0;
20 if has_generics {
21 panic!("cannot handle types with generics")
22 }
23
24 let _ = ty::parse(ast.clone());
26
27 let attrs = get_my_attributes(&ast.attrs).collect::<Vec<_>>();
29
30 match ast.data {
32 Data::Struct(st) => derive_struct(ast.ident, &attrs, st),
33 Data::Enum(e) => derive_enum(ast.ident, &attrs, e),
34 Data::Union(_) => panic!("Union not supported"),
35 }
36}