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
#![deny(warnings)]
#![deny(unused_lifetimes)]
// No unsafe code should ever be used in derive macros.
#![forbid(unsafe_code)]

use proc_macro::TokenStream;
use syn::{parse_macro_input, DeriveInput};

mod common;
mod decode;
mod encode;
mod enumeration;

#[proc_macro_derive(EncodableMessage, attributes(otopr))]
pub fn derive_encodable_message(ts: TokenStream) -> TokenStream {
    encode::derive_encodable_message(parse_macro_input!(ts as DeriveInput))
        .unwrap_or_else(|e| e.into_compile_error())
        .into()
}

#[proc_macro_derive(DecodableMessage, attributes(otopr))]
pub fn derive_decodable_message(ts: TokenStream) -> TokenStream {
    decode::derive_decodable_message(parse_macro_input!(ts as DeriveInput))
        .unwrap_or_else(|e| e.into_compile_error())
        .into()
}

#[proc_macro_derive(Enumeration)]
pub fn derive_enumeration(ts: TokenStream) -> TokenStream {
    enumeration::derive_enumeration(parse_macro_input!(ts as DeriveInput))
        .unwrap_or_else(|e| e.into_compile_error())
        .into()
}