martin-g commented on code in PR #1651:
URL: https://github.com/apache/avro/pull/1651#discussion_r856540773


##########
lang/rust/avro_derive/src/lib.rs:
##########
@@ -117,16 +119,24 @@ fn get_data_struct_schema_def(
         syn::Fields::Named(ref a) => {
             for (position, field) in a.named.iter().enumerate() {
                 let name = field.ident.as_ref().unwrap().to_string(); // we 
know everything has a name
-                let field_documented =
+                let field_attrs =
                     
FieldOptions::from_attributes(&field.attrs[..]).map_err(darling_to_syn)?;
-                let doc = preserve_optional(field_documented.doc);
+                let doc = preserve_optional(field_attrs.doc);
+                let default_value = match field_attrs.default {
+                    Some(default_value) => {
+                        quote! {

Review Comment:
   I will need your help with this!
   
   I changed it to:
   ```diff
   diff --git lang/rust/avro_derive/src/lib.rs lang/rust/avro_derive/src/lib.rs
   index 423625375..d8305452a 100644
   --- lang/rust/avro_derive/src/lib.rs
   +++ lang/rust/avro_derive/src/lib.rs
   @@ -124,14 +124,16 @@ fn get_data_struct_schema_def(
                    let doc = preserve_optional(field_attrs.doc);
                    let default_value = match field_attrs.default {
                        Some(default_value) => {
   +                        let default_value: serde_json::Value = 
serde_json::from_str(&default_value)
   +                            // .expect(format!("Invalid JSON: {:?}", 
default_value).as_str())
   +                            .map_err(|e| vec![syn::Error::new(error_span, 
e.to_string())])?;
                            quote! {
   -                            
Some(serde_json::from_str(#default_value).expect(format!("Invalid JSON: {:?}", 
#default_value).as_str()))
   +                            Some(#default_value)
                            }
                        }
                        None => quote! { None },
   ```
   
   but it fails with:
   ```
     Compiling apache-avro-derive v0.14.0 
(/home/martin/git/apache/avro/lang/rust/avro_derive)
   error[E0277]: the trait bound `Value: ToTokens` is not satisfied
      --> avro_derive/src/lib.rs:130:25
       |
   130 | /                         quote! {
   131 | |                             Some(#default_value)
   132 | |                         }
       | |_________________________^ the trait `ToTokens` is not implemented 
for `Value`
       |
       = note: this error originates in the macro `$crate::quote` (in Nightly 
builds, run with -Z macro-backtrace for more info)
   
   ```
   
   and I have no idea what to do :-/



-- 
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