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/// Emits metadata implementations on native targets only; Serde owns runtime codecs.
10#[proc_macro_derive(Wire, attributes(serde, wire))]
11pub fn derive_wire(input: TokenStream) -> TokenStream {
12    native_schema::expand(parse_macro_input!(input as DeriveInput))
13        .unwrap_or_else(syn::Error::into_compile_error)
14        .into()
15}
16
17// Generated local types and generics must not shadow names in the contract.
18fn fresh_ident(source: &str, base: &str) -> syn::Ident {
19    let mut name = base.to_owned();
20    while source.contains(&name) {
21        name.push('_');
22    }
23    format_ident!("{name}")
24}