(
input_span: Span,
ident: Ident,
generics: Generics,
container_attrs: NamedTypeOptions,
data: DataStruct,
)
| 42 | } |
| 43 | |
| 44 | fn normal( |
| 45 | ident: Ident, |
| 46 | generics: Generics, |
| 47 | container_attrs: NamedTypeOptions, |
| 48 | data: DataStruct, |
| 49 | ) -> Result<Implementation, Vec<syn::Error>> { |
| 50 | let record_fields_expr = match data.fields { |
| 51 | Fields::Named(fields) => named_fields_to_record_fields(fields, container_attrs.rename_all)?, |
| 52 | Fields::Unnamed(fields) => unnamed_fields_to_record_fields(fields)?, |
| 53 | Fields::Unit => { |
| 54 | quote! { |
| 55 | ::std::vec::Vec::new() |
| 56 | } |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | let record_doc = preserve_optional(container_attrs.doc.map(|s| quote! { #s.to_string() })); |
| 61 | let record_aliases = aliases(&container_attrs.aliases); |
| 62 | |
| 63 | let schema_expr = quote! { |
| 64 | ::apache_avro::schema::Schema::Record( |
| 65 | ::apache_avro::schema::RecordSchema::builder() |
| 66 | .aliases(#record_aliases) |
| 67 | .maybe_doc(#record_doc) |
| 68 | .fields(#record_fields_expr) |
| 69 | .name(name) |
| 70 | .build() |
| 71 | ) |
| 72 | }; |
| 73 | |
| 74 | let record_fields_expr = quote! { |
| 75 | ::std::option::Option::Some(#record_fields_expr) |
| 76 | }; |
| 77 | |
| 78 | Ok(Implementation::named( |
| 79 | ident, |
| 80 | generics, |
| 81 | &container_attrs.name, |
| 82 | schema_expr, |
| 83 | Some(record_fields_expr), |
| 84 | container_attrs |
| 85 | .default |
| 86 | .map(json_value_expr) |
| 87 | .map(|t| quote! { ::std::option::Option::Some(#t)}), |
| 88 | )) |
| 89 | } |
| 90 | |
| 91 | fn transparent( |
| 92 | input_span: Span, |
| 93 | ident: Ident, |
| 94 | generics: Generics, |
| 95 | data: DataStruct, |
| 96 | ) -> Result<Implementation, Vec<syn::Error>> { |
| 97 | match data.fields { |
| 98 | Fields::Named(fields_named) => { |
| 99 | let mut found = None; |
| 100 | for field in fields_named.named { |
| 101 | let attrs = FieldOptions::new(&field.attrs, field.span())?; |
no test coverage detected