Skip to main content

wincode_derive_arcium_fork/
lib.rs

1//! Derive macros for `SchemaWrite` and `SchemaRead`.
2//!
3//! Note using this on packed structs is UB.
4//!
5//! Refer to the [`wincode`](https://docs.rs/wincode) crate for examples.
6use {
7    proc_macro::TokenStream,
8    syn::{parse_macro_input, DeriveInput},
9};
10
11mod assert_zero_copy;
12mod common;
13mod schema_read;
14mod schema_write;
15
16/// Implement `SchemaWrite` for a struct or enum.
17#[proc_macro_derive(SchemaWrite, attributes(wincode))]
18pub fn derive_schema_write(input: TokenStream) -> TokenStream {
19    let input = parse_macro_input!(input as DeriveInput);
20    match schema_write::generate(input) {
21        Ok(tokens) => tokens.into(),
22        Err(e) => e.write_errors().into(),
23    }
24}
25
26/// Implement `SchemaRead` for a struct or enum.
27#[proc_macro_derive(SchemaRead, attributes(wincode))]
28pub fn derive_schema_read(input: TokenStream) -> TokenStream {
29    let input = parse_macro_input!(input as DeriveInput);
30    match schema_read::generate(input) {
31        Ok(tokens) => tokens.into(),
32        Err(e) => e.write_errors().into(),
33    }
34}