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


##########
avro_derive/src/attributes/mod.rs:
##########
@@ -0,0 +1,206 @@
+use darling::FromAttributes;
+use proc_macro2::Span;
+use syn::Attribute;
+
+use crate::{case::RenameRule, darling_to_syn};
+
+pub mod avro;
+pub mod serde;
+
+#[derive(Default)]
+pub struct NamedTypeOptions {
+    pub name: Option<String>,
+    pub namespace: Option<String>,
+    pub doc: Option<String>,
+    pub alias: Vec<String>,
+    pub rename_all: RenameRule,
+}
+
+impl NamedTypeOptions {
+    pub fn new(attributes: &[Attribute], span: Span) -> Result<Self, 
Vec<syn::Error>> {
+        let avro =
+            
avro::ContainerAttributes::from_attributes(attributes).map_err(darling_to_syn)?;
+        let serde =
+            
serde::ContainerAttributes::from_attributes(attributes).map_err(darling_to_syn)?;
+
+        // Collect errors so user gets all feedback at once
+        let mut errors = Vec::new();
+
+        // Check for any Serde attributes that are hard errors
+        if serde.tag.is_some()
+            || serde.content.is_some()
+            || serde.untagged
+            || serde.variant_identifier
+            || serde.field_identifier
+        {
+            errors.push(syn::Error::new(
+                span,
+                "AvroSchema derive does not support changing the tagging Serde 
generates (`tag`, `content`, `untagged`, `variant_identifier`, 
`field_identifier`)",
+            ));
+        }
+        if serde.remote.is_some() {
+            errors.push(syn::Error::new(
+                span,
+                "AvroSchema derive does not support the Serde `remote` 
attribute",
+            ));
+        }
+        if serde.transparent {
+            errors.push(syn::Error::new(
+                span,
+                "AvroSchema derive does not support Serde `transparent` 
attribute",
+            ))
+        }
+        if serde.rename_all.deserialize != serde.rename_all.serialize {
+            errors.push(syn::Error::new(
+                span,
+                "AvroSchema derive does not support different rename rules for 
serializing and deserializing (`rename_all(serialize = \"..\", deserialize = 
\"..\")`)"
+            ))
+        }
+
+        // Check for conflicts between Serde and Avro
+        if avro.rename_all != RenameRule::None && serde.rename_all.serialize 
!= avro.rename_all {
+            errors.push(syn::Error::new(
+                span,
+                "#[avro(rename_all = \"..\")] must match #[serde(rename_all = 
\"..\")], it's also deprecated. Please use only `#[serde(rename_all = 
\"..\")]`",
+            ))

Review Comment:
   ```suggestion
               ));
   ```



##########
avro_derive/src/attributes/mod.rs:
##########
@@ -0,0 +1,206 @@
+use darling::FromAttributes;
+use proc_macro2::Span;
+use syn::Attribute;
+
+use crate::{case::RenameRule, darling_to_syn};
+
+pub mod avro;
+pub mod serde;
+
+#[derive(Default)]
+pub struct NamedTypeOptions {
+    pub name: Option<String>,
+    pub namespace: Option<String>,
+    pub doc: Option<String>,
+    pub alias: Vec<String>,
+    pub rename_all: RenameRule,
+}
+
+impl NamedTypeOptions {
+    pub fn new(attributes: &[Attribute], span: Span) -> Result<Self, 
Vec<syn::Error>> {
+        let avro =
+            
avro::ContainerAttributes::from_attributes(attributes).map_err(darling_to_syn)?;
+        let serde =
+            
serde::ContainerAttributes::from_attributes(attributes).map_err(darling_to_syn)?;
+
+        // Collect errors so user gets all feedback at once
+        let mut errors = Vec::new();
+
+        // Check for any Serde attributes that are hard errors
+        if serde.tag.is_some()
+            || serde.content.is_some()
+            || serde.untagged
+            || serde.variant_identifier
+            || serde.field_identifier
+        {
+            errors.push(syn::Error::new(
+                span,
+                "AvroSchema derive does not support changing the tagging Serde 
generates (`tag`, `content`, `untagged`, `variant_identifier`, 
`field_identifier`)",
+            ));
+        }
+        if serde.remote.is_some() {
+            errors.push(syn::Error::new(
+                span,
+                "AvroSchema derive does not support the Serde `remote` 
attribute",
+            ));
+        }
+        if serde.transparent {
+            errors.push(syn::Error::new(
+                span,
+                "AvroSchema derive does not support Serde `transparent` 
attribute",
+            ))

Review Comment:
   ```suggestion
               ));
   ```



##########
avro_derive/src/attributes/mod.rs:
##########
@@ -0,0 +1,206 @@
+use darling::FromAttributes;
+use proc_macro2::Span;
+use syn::Attribute;
+
+use crate::{case::RenameRule, darling_to_syn};
+
+pub mod avro;
+pub mod serde;
+
+#[derive(Default)]
+pub struct NamedTypeOptions {
+    pub name: Option<String>,
+    pub namespace: Option<String>,
+    pub doc: Option<String>,
+    pub alias: Vec<String>,
+    pub rename_all: RenameRule,
+}
+
+impl NamedTypeOptions {
+    pub fn new(attributes: &[Attribute], span: Span) -> Result<Self, 
Vec<syn::Error>> {
+        let avro =
+            
avro::ContainerAttributes::from_attributes(attributes).map_err(darling_to_syn)?;
+        let serde =
+            
serde::ContainerAttributes::from_attributes(attributes).map_err(darling_to_syn)?;
+
+        // Collect errors so user gets all feedback at once
+        let mut errors = Vec::new();
+
+        // Check for any Serde attributes that are hard errors
+        if serde.tag.is_some()
+            || serde.content.is_some()
+            || serde.untagged
+            || serde.variant_identifier
+            || serde.field_identifier
+        {
+            errors.push(syn::Error::new(
+                span,
+                "AvroSchema derive does not support changing the tagging Serde 
generates (`tag`, `content`, `untagged`, `variant_identifier`, 
`field_identifier`)",
+            ));
+        }
+        if serde.remote.is_some() {
+            errors.push(syn::Error::new(
+                span,
+                "AvroSchema derive does not support the Serde `remote` 
attribute",
+            ));
+        }
+        if serde.transparent {
+            errors.push(syn::Error::new(
+                span,
+                "AvroSchema derive does not support Serde `transparent` 
attribute",
+            ))
+        }
+        if serde.rename_all.deserialize != serde.rename_all.serialize {
+            errors.push(syn::Error::new(
+                span,
+                "AvroSchema derive does not support different rename rules for 
serializing and deserializing (`rename_all(serialize = \"..\", deserialize = 
\"..\")`)"
+            ))

Review Comment:
   ```suggestion
               ));
   ```



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