martin-g commented on code in PR #561:
URL: https://github.com/apache/avro-rs/pull/561#discussion_r3465048132


##########
avro_derive/src/structs.rs:
##########
@@ -1,3 +1,5 @@
+use crate::attributes::{FieldOptions, NamedTypeOptions};

Review Comment:
   These should be below the ASLv2 header comment.



##########
avro_derive/src/enums/plain.rs:
##########
@@ -17,25 +17,27 @@
 
 use crate::attributes::{NamedTypeOptions, VariantOptions};
 use crate::case::RenameRule;
-use crate::enums::default_enum_variant;
+use crate::implementation::Implementation;
 use crate::{aliases, preserve_optional};
-use proc_macro2::{Span, TokenStream};
+use proc_macro2::{Ident, Span};
 use quote::quote;
 use syn::spanned::Spanned;
-use syn::{DataEnum, Fields};
+use syn::{Attribute, DataEnum, Fields, Generics, Meta};
 
-pub fn schema_def(
-    container_attrs: &NamedTypeOptions,
-    data_enum: &DataEnum,
-    ident_span: Span,
-) -> Result<TokenStream, Vec<syn::Error>> {
+pub fn to_implementation(
+    input_span: Span,
+    ident: Ident,
+    generics: Generics,
+    container_attrs: NamedTypeOptions,
+    data: DataEnum,
+) -> Result<Implementation, Vec<syn::Error>> {
     let doc = preserve_optional(container_attrs.doc.as_ref());
     let enum_aliases = aliases(&container_attrs.aliases);
-    if data_enum.variants.iter().all(|v| Fields::Unit == v.fields) {
-        let default_value = default_enum_variant(data_enum, ident_span)?;
+    if data.variants.iter().all(|v| Fields::Unit == v.fields) {
+        let default_value = default_enum_variant(&data, input_span)?;
         let default = preserve_optional(default_value);

Review Comment:
   I wonder should `container_attrs.rename_all` be used also for the `default` 
value ?!



##########
avro_derive/src/attributes/mod.rs:
##########
@@ -112,20 +112,19 @@ impl NamedTypeOptions {
 
         let doc = avro.doc.or_else(|| extract_rustdoc(attributes));
 
-        let default = match avro.default {
-            None => quote! { None },
-            Some(default_value) => {
-                let _: serde_json::Value =
-                    serde_json::from_str(&default_value[..]).map_err(|e| {
-                        vec![syn::Error::new(
-                            ident.span(),
-                            format!("Invalid Avro `default` JSON: \n{e}"),
-                        )]
-                    })?;
-                quote! {
-                    
Some(::serde_json::from_str(#default_value).expect(format!("Invalid JSON: 
{:?}", #default_value).as_str()))
-                }
-            }
+        let default = if let Some(default_value) = avro.default {
+            let _: serde_json::Value =
+                serde_json::from_str(default_value.as_str()).map_err(|e| {
+                    vec![syn::Error::new(
+                        ident.span(),
+                        format!("Invalid Avro `default` JSON: \n{e}"),
+                    )]
+                })?;
+            Some(quote! {
+                
::std::option::Option::Some(::serde_json::from_str(#default_value).expect(format!("Invalid
 JSON: {:?}", #default_value).as_str()))

Review Comment:
   ```suggestion
                   
::std::option::Option::Some(::serde_json::from_str(#default_value).expect(concat!("Invalid
 JSON: ", #default_value)))
   ```
   Same, but at compile time.



##########
avro_derive/src/structs.rs:
##########
@@ -162,9 +187,18 @@ pub fn get_transparent_struct_schema_def(
             }
 
             if let Some((field, attrs)) = found {
-                Ok((
-                    field_to_schema_expr(&field, attrs.with.clone())?,
-                    field_to_record_fields_expr(&field, attrs.with)?,
+                let field_default_expr = if container_attrs.default.is_none() {

Review Comment:
   Hm. If there is no container default then use the field's default. Shouldn't 
the field's default overwrite the container's one ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to