Skip to main content

tpack_macros/
lib.rs

1mod ast;
2mod emit;
3mod parse;
4mod util;
5
6use proc_macro::TokenStream;
7use util::compile_error;
8
9#[proc_macro_derive(TpackSerialize, attributes(tpack))]
10pub fn derive_tpack_serialize(input: TokenStream) -> TokenStream {
11    match parse::parse_item(input).and_then(|item| emit::impl_serialize(&item)) {
12        Ok(tokens) => tokens,
13        Err(err) => compile_error(&err),
14    }
15}
16
17#[proc_macro_derive(TpackDeserialize, attributes(tpack))]
18pub fn derive_tpack_deserialize(input: TokenStream) -> TokenStream {
19    match parse::parse_item(input).and_then(|item| emit::impl_deserialize(&item)) {
20        Ok(tokens) => tokens,
21        Err(err) => compile_error(&err),
22    }
23}