(
ast: &syn::DeriveInput,
attrs: ForyAttrs,
runtime_root: proc_macro2::TokenStream,
)
| 39 | } |
| 40 | |
| 41 | pub fn derive_serializer( |
| 42 | ast: &syn::DeriveInput, |
| 43 | attrs: ForyAttrs, |
| 44 | runtime_root: proc_macro2::TokenStream, |
| 45 | ) -> TokenStream { |
| 46 | let name = &ast.ident; |
| 47 | let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl(); |
| 48 | |
| 49 | use crate::object::util::{clear_struct_context, set_struct_context}; |
| 50 | set_struct_context(&name.to_string(), attrs.debug_enabled); |
| 51 | |
| 52 | // Check if ForyDefault is already derived/implemented |
| 53 | let has_existing_default = has_existing_default(ast, "ForyDefault"); |
| 54 | let default_impl = if !has_existing_default { |
| 55 | generate_default_impl(ast, attrs.generate_default) |
| 56 | } else { |
| 57 | quote! {} |
| 58 | }; |
| 59 | let send_sync_tokens = generate_send_sync_tokens(ast); |
| 60 | let serializer_send_sync_ts = send_sync_tokens.serializer.clone(); |
| 61 | |
| 62 | // StructSerializer |
| 63 | let ( |
| 64 | actual_type_id_ts, |
| 65 | get_sorted_field_names_ts, |
| 66 | fields_info_ts, |
| 67 | variants_fields_info_ts, |
| 68 | read_compatible_ts, |
| 69 | read_compatible_as_send_sync_any_ts, |
| 70 | enum_variant_meta_types, |
| 71 | ) = match &ast.data { |
| 72 | syn::Data::Struct(s) => { |
| 73 | let source_fields = source_fields(&s.fields); |
| 74 | let fields = extract_fields(&source_fields); |
| 75 | let actual_type_id_ts = if attrs.evolving == Some(false) { |
| 76 | misc::gen_actual_type_id_no_evolving() |
| 77 | } else { |
| 78 | misc::gen_actual_type_id() |
| 79 | }; |
| 80 | ( |
| 81 | actual_type_id_ts, |
| 82 | misc::gen_get_sorted_field_names(&fields), |
| 83 | misc::gen_field_fields_info(&source_fields), |
| 84 | quote! { ::std::result::Result::Ok(::std::vec::Vec::new()) }, // No variants for structs |
| 85 | read::gen_read_compatible(&source_fields), |
| 86 | send_sync_tokens.struct_read_compatible.clone(), |
| 87 | vec![], // No variant meta types for structs |
| 88 | ) |
| 89 | } |
| 90 | syn::Data::Enum(s) => { |
| 91 | // Generate variant meta types for named variants |
| 92 | let variant_meta_types = |
| 93 | derive_enum::gen_all_variant_meta_types_with_enum_name(name, s); |
| 94 | ( |
| 95 | derive_enum::gen_actual_type_id(s), |
| 96 | quote! { &[] }, |
| 97 | derive_enum::gen_field_fields_info(s), |
| 98 | derive_enum::gen_variants_fields_info(name, s), |
nothing calls this directly
no test coverage detected