cgp_macro_lib/entrypoints/
cgp_record.rs1use proc_macro2::TokenStream;
2use quote::quote;
3use syn::{ItemStruct, parse2};
4
5use crate::derive_build_field_from_struct;
6use crate::derive_has_fields::derive_has_fields_impls_from_struct;
7use crate::field::derive_has_field_impls_from_struct;
8
9pub fn derive_cgp_record(body: TokenStream) -> syn::Result<TokenStream> {
10 let item_struct = parse2(body)?;
11 derive_cgp_record_from_struct(&item_struct)
12}
13
14pub fn derive_cgp_record_from_struct(item_struct: &ItemStruct) -> syn::Result<TokenStream> {
15 let has_field_impls = derive_has_field_impls_from_struct(item_struct);
16 let has_fields_impls = derive_has_fields_impls_from_struct(item_struct)?;
17 let build_field_impls = derive_build_field_from_struct(item_struct)?;
18
19 Ok(quote! {
20 #( #has_field_impls )*
21 #( #has_fields_impls )*
22 #build_field_impls
23 })
24}