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


##########
avro_derive/src/attributes/serde.rs:
##########
@@ -0,0 +1,298 @@
+//! Attribute parsing for Serde attributes
+//!
+//! # Serde attributes
+//! This module only parses the minimal amount to be able to read Serde 
attributes. This means
+//! most attributes are decoded as an `Option<String>` as the actual content 
is not relevant.
+//! Attributes which are not needed by the derive are prefixed with a `_` as 
we can't ignore them
+//! (this would be a compile error).
+//!
+//! If Serde adds new attributes they need to be added here too.
+
+use darling::{FromAttributes, FromMeta};
+use syn::Expr;
+
+use crate::case::RenameRule;
+
+// from_expr is used for `rename_all = ".."`
+// FromMeta is used for `rename_all(serialize = "..", ..)`
+#[derive(Debug, Default, FromMeta, PartialEq, Eq)]
+#[darling(from_expr = RenameAll::from_expr)]
+pub struct RenameAll {
+    #[darling(default)]
+    pub serialize: RenameRule,
+    #[darling(default)]
+    pub deserialize: RenameRule,
+}
+
+impl From<RenameRule> for RenameAll {
+    fn from(value: RenameRule) -> Self {
+        Self {
+            serialize: value,
+            deserialize: value,
+        }
+    }
+}
+
+impl RenameAll {
+    fn from_expr(expr: &Expr) -> darling::Result<Self> {
+        let Expr::Lit(lit) = expr else {
+            return Err(darling::Error::custom("Expected a string or a 
tuple!"));
+        };
+        let rule = RenameRule::from_value(&lit.lit)?;
+        Ok(RenameAll::from(rule))
+    }
+}
+
+#[derive(Debug, FromMeta, PartialEq)]
+#[darling(from_expr = |expr| Ok(SerdeDefault::Expr(expr.clone())))]
+pub enum SerdeDefault {
+    #[darling(word, skip)]
+    UseTrait,
+    Expr(Expr),
+}
+
+/// All Serde attributes that a container can have.
+#[derive(Debug, FromAttributes)]
+#[darling(attributes(serde))]
+pub struct ContainerAttributes {
+    #[darling(rename = "rename")]
+    /// Rename this container.
+    pub _rename: Option<String>,
+    /// Rename all the fields (if this is a struct) or variants (if this is an 
enum) according to the given case convention.
+    #[darling(default)]
+    pub rename_all: RenameAll,
+    /// Rename all the fields of the struct variants in this enum.
+    #[darling(default, rename = "rename_all_fields")]
+    pub _rename_all_fields: RenameAll,
+    /// Error when encountering unknown fields when deserialising.
+    #[darling(default, rename = "deny_unknown_fields")]
+    pub _deny_unknown_fields: bool,
+    /// Add/expect a tag during serialisation.
+    ///
+    /// When used on a struct, this adds an extra field which is not in the 
schema definition.
+    /// When used on an enum, serde transforms it into a struct which does not 
match the schema definition.
+    pub tag: Option<String>,
+    /// Put the content in a field with this name.
+    pub content: Option<String>,
+    /// This makes the enum transparent, (de)serializing based on the variant 
directly.
+    ///
+    /// This does not match the schema definition.
+    #[darling(default)]
+    pub untagged: bool,
+    /// Add a bound to the Serialize/Deserialize trait.
+    #[darling(default, rename = "bound")]
+    pub _bound: Option<String>,
+    /// When deserializing, any missing fields should be filled in from the 
struct's implementation of `Default`.
+    #[darling(rename = "default")]
+    pub _default: Option<SerdeDefault>,
+    /// This type is the serde implementation for a "remote" type.
+    ///
+    /// This makes the (de)serialisation use/return a different type.
+    pub remote: Option<String>,
+    /// Directly use the inner type for (de)serialisation.
+    #[darling(default)]
+    pub transparent: bool,
+    /// Deserialize using the given type and then convert to this type with 
`From`.
+    #[darling(default, rename = "from")]
+    pub _from: Option<String>,
+    /// Deserialize using the given type and then convert to this type with 
`TryFrom`.
+    #[darling(default, rename = "try_from")]
+    pub _try_from: Option<String>,
+    /// Convert this type to the given type using `Into` and then serialize 
using the given type.
+    #[darling(default, rename = "into")]
+    pub _into: Option<String>,
+    /// Use the Serde API at this path.
+    #[darling(default, rename = "crate")]
+    pub _crate: Option<String>,
+    /// Custom error text.
+    #[darling(default, rename = "expecting")]
+    pub _expecting: Option<String>,
+    /// This does something with tags, which are incompatible.
+    #[darling(default)]
+    pub variant_identifier: bool,
+    /// This does something with tags,  `` which are incompatible.

Review Comment:
   Probably a copy-paste error



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