rkyv_with/
lib.rs

1#![doc = include_str!("../README.md")]
2
3use proc_macro::TokenStream;
4use syn::{parse_macro_input, DeriveInput};
5
6mod archive_with;
7mod deserialize_with;
8mod util;
9
10const ATTR: &str = "archive_with";
11
12/// Derive macro to implement rkyv's `ArchiveWith` and `SerializeWith` traits.
13///
14/// See the crate root for more information.
15#[proc_macro_derive(ArchiveWith, attributes(archive_with))]
16pub fn archive_with(input: TokenStream) -> TokenStream {
17    let input = parse_macro_input!(input as DeriveInput);
18
19    match archive_with::derive(input) {
20        Ok(tokens) => tokens.into(),
21        Err(err) => err.to_compile_error().into(),
22    }
23}
24
25/// Derive macro to implement rkyv's `DeserializeWith` trait.
26///
27/// See the crate root for more information.
28#[proc_macro_derive(DeserializeWith, attributes(archive_with))]
29pub fn deserialize_with(input: TokenStream) -> TokenStream {
30    let input = parse_macro_input!(input as DeriveInput);
31
32    match deserialize_with::derive(input) {
33        Ok(tokens) => tokens.into(),
34        Err(err) => err.to_compile_error().into(),
35    }
36}