Kriskras99 commented on code in PR #377:
URL: https://github.com/apache/avro-rs/pull/377#discussion_r2660929093


##########
avro_derive/src/attributes/mod.rs:
##########
@@ -0,0 +1,202 @@
+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",
+            ))
+        }
+        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 = 
\"..\")]`",
+            ))
+        }
+
+        if !errors.is_empty() {
+            return Err(errors);
+        }
+
+        Ok(Self {
+            name: avro.name,
+            namespace: avro.namespace,
+            doc: avro.doc,
+            alias: avro.alias,
+            rename_all: serde.rename_all.serialize,
+        })
+    }
+}
+
+pub struct FieldOptions {
+    pub doc: Option<String>,
+    pub default: Option<String>,
+    pub alias: Vec<String>,
+    pub rename: Option<String>,
+    pub skip: bool,
+    pub flatten: bool,
+}
+
+impl FieldOptions {
+    pub fn new(attributes: &[Attribute], span: Span) -> Result<Self, 
Vec<syn::Error>> {
+        let avro = 
avro::FieldAttributes::from_attributes(attributes).map_err(darling_to_syn)?;
+        let serde = 
serde::FieldAttributes::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.getter.is_some() {
+            errors.push(syn::Error::new(
+                span,
+                "AvroSchema derive does not support the Serde `getter` 
attribute",
+            ));
+        }
+
+        // Check for conflicts between Serde and Avro
+        if avro.skip && !serde.skip {
+            errors.push(syn::Error::new(
+                span,
+                "`#[avro(skip)]` requires `#[serde(skip)]`, it's also 
deprecated. Please use only `#[serde(skip)]`"

Review Comment:
   Added in the new commit



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