Skip to main content

ic_wire_derive/
lib.rs

1//! Host metadata for Serde contracts; no serializer generation.
2use proc_macro::TokenStream;
3use quote::format_ident;
4use syn::{DeriveInput, parse_macro_input};
5
6mod native_schema;
7
8/// Describe ordinary Serde layouts for host-side TypeScript generation, without IDs.
9#[proc_macro_derive(Wire, attributes(serde, wire))]
10pub fn derive_wire(input: TokenStream) -> TokenStream {
11    native_schema::expand(parse_macro_input!(input as DeriveInput))
12        .unwrap_or_else(syn::Error::into_compile_error)
13        .into()
14}
15
16// Generated local types and generics must not shadow names in the contract.
17fn fresh_ident(source: &str, base: &str) -> syn::Ident {
18    let mut name = base.to_owned();
19    while source.contains(&name) {
20        name.push('_');
21    }
22    format_ident!("{name}")
23}