Skip to main content

synctick_derive/
lib.rs

1//! Derives for stable session payloads and deterministic state fingerprints.
2use proc_macro::TokenStream;
3use syn::{DeriveInput, parse_macro_input};
4
5mod hashing;
6mod shared;
7mod wire;
8
9/// Generate bounded codec passes for structs and explicitly tagged enums.
10#[proc_macro_derive(Wire, attributes(wire))]
11pub fn derive_wire(input: TokenStream) -> TokenStream {
12    let input = parse_macro_input!(input as DeriveInput);
13    wire::expand(&input)
14        .unwrap_or_else(syn::Error::into_compile_error)
15        .into()
16}
17
18/// Hash fields in declaration order, with explicit byte tags for enums.
19///
20/// Fields marked `#[stable_hash(skip)]` contribute no bytes and need no hash bound.
21/// Only skip recomputable caches or presentation state, never authoritative state.
22/// Tags may use `stable_hash` or reuse a `wire` tag attribute, but not both.
23#[proc_macro_derive(StableHash, attributes(stable_hash, wire))]
24pub fn derive_stable_hash(input: TokenStream) -> TokenStream {
25    let input = parse_macro_input!(input as DeriveInput);
26    hashing::expand(&input)
27        .unwrap_or_else(syn::Error::into_compile_error)
28        .into()
29}