Skip to main content

tycho_types_abi_proc/
lib.rs

1mod derive_from_abi;
2mod derive_into_abi;
3mod derive_with_abi_type;
4mod internals;
5
6use proc_macro::TokenStream;
7use quote::quote;
8
9#[proc_macro_derive(IntoAbi, attributes(abi))]
10pub fn derive_into_abi(input: TokenStream) -> TokenStream {
11    let input = syn::parse_macro_input!(input as syn::DeriveInput);
12    derive_into_abi::impl_derive(input)
13        .unwrap_or_else(to_compile_errors)
14        .into()
15}
16
17#[proc_macro_derive(WithAbiType, attributes(abi))]
18pub fn derive_with_abi_type(input: TokenStream) -> TokenStream {
19    let input = syn::parse_macro_input!(input as syn::DeriveInput);
20    derive_with_abi_type::impl_derive(input)
21        .unwrap_or_else(to_compile_errors)
22        .into()
23}
24
25#[proc_macro_derive(FromAbi, attributes(abi))]
26pub fn derive_from_abi(input: TokenStream) -> TokenStream {
27    let input = syn::parse_macro_input!(input as syn::DeriveInput);
28    derive_from_abi::impl_derive(input)
29        .unwrap_or_else(to_compile_errors)
30        .into()
31}
32
33fn to_compile_errors(errors: Vec<syn::Error>) -> proc_macro2::TokenStream {
34    let compile_errors = errors.iter().map(syn::Error::to_compile_error);
35    quote!(#(#compile_errors)*)
36}