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


##########
avro/src/schema/record/schema.rs:
##########
@@ -82,11 +82,13 @@ impl<S: record_schema_builder::State> 
RecordSchemaBuilder<S> {
 
 /// Calculate the lookup table for the given fields.
 fn calculate_lookup_table(fields: &[RecordField]) -> BTreeMap<String, usize> {
-    fields
+    let map: BTreeMap<_, _> = fields
         .iter()
         .enumerate()
         .map(|(i, field)| (field.name.clone(), i))
-        .collect()
+        .collect();
+    assert_eq!(map.len(), fields.len(), "Duplicate field names found");

Review Comment:
   ```suggestion
       debug_assert_eq!(map.len(), fields.len(), "Duplicate field names found");
   ```



##########
avro_derive/src/enums/mod.rs:
##########
@@ -37,23 +45,224 @@ pub fn to_implementation(
             "AvroSchema: `#[serde(transparent)]` is only supported on structs",
         )]);
     }
-    if data
-        .variants
-        .iter()
-        .filter(|v| {
-            // Filter skipped variants, if the attributes fail to parse we'll 
also filter them out
-            // `plain` will throw proper errors for that.
-            VariantOptions::new(&v.attrs, v.span())
-                .map(|o| !o.skip)
-                .unwrap_or(false)
-        })
-        .all(|v| Fields::Unit == v.fields)
-    {
-        plain::to_implementation(input_span, ident, generics, container_attrs, 
data)
-    } else {
-        Err(vec![syn::Error::new(
+
+    match &container_attrs.repr {
+        None => {
+            if data
+                .variants
+                .iter()
+                .filter(|v| {
+                    // Filter skipped variants, if the attributes fail to 
parse we'll also filter them out
+                    // `plain` will throw proper errors for that.
+                    VariantOptions::new(&v.attrs, v.span())
+                        .map(|o| !o.skip)
+                        .unwrap_or(false)
+                })
+                .all(|v| Fields::Unit == v.fields)
+            {
+                plain::to_implementation(input_span, ident, generics, 
container_attrs, data)
+            } else {
+                union_of_records::to_implementation(ident, generics, 
container_attrs, data)
+            }
+        }
+        Some(Repr::Enum) => {
+            plain::to_implementation(input_span, ident, generics, 
container_attrs, data)
+        }
+        Some(Repr::BareUnion { .. }) => {
+            bare_union::to_implementation(ident, generics, container_attrs, 
data)
+        }
+        Some(Repr::UnionOfRecords) => {
+            union_of_records::to_implementation(ident, generics, 
container_attrs, data)
+        }
+        Some(Repr::RecordTagContent { .. }) => 
record_tag_content::to_implementation(
             input_span,
-            "AvroSchema: derive does not work for enums with non unit structs",
-        )])
+            ident,
+            generics,
+            container_attrs,
+            data,
+        ),
+        Some(Repr::RecordInternallyTagged { .. }) => {
+            record_internally_tagged::to_implementation(ident, generics, 
container_attrs, data)
+        }
+    }
+}
+
+fn newtype_extra_attribute_checks(
+    options: FieldOptions,
+    span: Span,
+) -> Result<FieldOptions, Vec<syn::Error>> {
+    let mut errors = Vec::new();
+    if options.doc.is_some() {
+        errors.push(syn::Error::new(
+            span,
+            r#"AvroSchema: `#[avro(doc = "..")]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")`"#

Review Comment:
   ```suggestion
               r#"AvroSchema: `#[avro(doc = "..")]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")]`"#
   ```



##########
avro_derive/src/enums/mod.rs:
##########
@@ -37,23 +45,224 @@ pub fn to_implementation(
             "AvroSchema: `#[serde(transparent)]` is only supported on structs",
         )]);
     }
-    if data
-        .variants
-        .iter()
-        .filter(|v| {
-            // Filter skipped variants, if the attributes fail to parse we'll 
also filter them out
-            // `plain` will throw proper errors for that.
-            VariantOptions::new(&v.attrs, v.span())
-                .map(|o| !o.skip)
-                .unwrap_or(false)
-        })
-        .all(|v| Fields::Unit == v.fields)
-    {
-        plain::to_implementation(input_span, ident, generics, container_attrs, 
data)
-    } else {
-        Err(vec![syn::Error::new(
+
+    match &container_attrs.repr {
+        None => {
+            if data
+                .variants
+                .iter()
+                .filter(|v| {
+                    // Filter skipped variants, if the attributes fail to 
parse we'll also filter them out
+                    // `plain` will throw proper errors for that.
+                    VariantOptions::new(&v.attrs, v.span())
+                        .map(|o| !o.skip)
+                        .unwrap_or(false)
+                })
+                .all(|v| Fields::Unit == v.fields)
+            {
+                plain::to_implementation(input_span, ident, generics, 
container_attrs, data)
+            } else {
+                union_of_records::to_implementation(ident, generics, 
container_attrs, data)
+            }
+        }
+        Some(Repr::Enum) => {
+            plain::to_implementation(input_span, ident, generics, 
container_attrs, data)
+        }
+        Some(Repr::BareUnion { .. }) => {
+            bare_union::to_implementation(ident, generics, container_attrs, 
data)
+        }
+        Some(Repr::UnionOfRecords) => {
+            union_of_records::to_implementation(ident, generics, 
container_attrs, data)
+        }
+        Some(Repr::RecordTagContent { .. }) => 
record_tag_content::to_implementation(
             input_span,
-            "AvroSchema: derive does not work for enums with non unit structs",
-        )])
+            ident,
+            generics,
+            container_attrs,
+            data,
+        ),
+        Some(Repr::RecordInternallyTagged { .. }) => {
+            record_internally_tagged::to_implementation(ident, generics, 
container_attrs, data)
+        }
+    }
+}
+
+fn newtype_extra_attribute_checks(
+    options: FieldOptions,
+    span: Span,
+) -> Result<FieldOptions, Vec<syn::Error>> {
+    let mut errors = Vec::new();
+    if options.doc.is_some() {
+        errors.push(syn::Error::new(
+            span,
+            r#"AvroSchema: `#[avro(doc = "..")]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")`"#
+        ));
+    }
+    if !matches!(options.default, FieldDefault::Trait) {
+        errors.push(syn::Error::new(
+            span,
+            r#"AvroSchema: `#[avro(default = ..)]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")`"#

Review Comment:
   ```suggestion
               r#"AvroSchema: `#[avro(default = ..)]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")]`"#
   ```



##########
avro_derive/src/enums/mod.rs:
##########
@@ -37,23 +45,224 @@ pub fn to_implementation(
             "AvroSchema: `#[serde(transparent)]` is only supported on structs",
         )]);
     }
-    if data
-        .variants
-        .iter()
-        .filter(|v| {
-            // Filter skipped variants, if the attributes fail to parse we'll 
also filter them out
-            // `plain` will throw proper errors for that.
-            VariantOptions::new(&v.attrs, v.span())
-                .map(|o| !o.skip)
-                .unwrap_or(false)
-        })
-        .all(|v| Fields::Unit == v.fields)
-    {
-        plain::to_implementation(input_span, ident, generics, container_attrs, 
data)
-    } else {
-        Err(vec![syn::Error::new(
+
+    match &container_attrs.repr {
+        None => {
+            if data
+                .variants
+                .iter()
+                .filter(|v| {
+                    // Filter skipped variants, if the attributes fail to 
parse we'll also filter them out
+                    // `plain` will throw proper errors for that.
+                    VariantOptions::new(&v.attrs, v.span())
+                        .map(|o| !o.skip)
+                        .unwrap_or(false)
+                })
+                .all(|v| Fields::Unit == v.fields)
+            {
+                plain::to_implementation(input_span, ident, generics, 
container_attrs, data)
+            } else {
+                union_of_records::to_implementation(ident, generics, 
container_attrs, data)
+            }
+        }
+        Some(Repr::Enum) => {
+            plain::to_implementation(input_span, ident, generics, 
container_attrs, data)
+        }
+        Some(Repr::BareUnion { .. }) => {
+            bare_union::to_implementation(ident, generics, container_attrs, 
data)
+        }
+        Some(Repr::UnionOfRecords) => {
+            union_of_records::to_implementation(ident, generics, 
container_attrs, data)
+        }
+        Some(Repr::RecordTagContent { .. }) => 
record_tag_content::to_implementation(
             input_span,
-            "AvroSchema: derive does not work for enums with non unit structs",
-        )])
+            ident,
+            generics,
+            container_attrs,
+            data,
+        ),
+        Some(Repr::RecordInternallyTagged { .. }) => {
+            record_internally_tagged::to_implementation(ident, generics, 
container_attrs, data)
+        }
+    }
+}
+
+fn newtype_extra_attribute_checks(
+    options: FieldOptions,
+    span: Span,
+) -> Result<FieldOptions, Vec<syn::Error>> {
+    let mut errors = Vec::new();
+    if options.doc.is_some() {
+        errors.push(syn::Error::new(
+            span,
+            r#"AvroSchema: `#[avro(doc = "..")]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")`"#
+        ));
+    }
+    if !matches!(options.default, FieldDefault::Trait) {
+        errors.push(syn::Error::new(
+            span,
+            r#"AvroSchema: `#[avro(default = ..)]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")`"#
+        ));
+    }
+    if !options.alias.is_empty() {
+        errors.push(syn::Error::new(
+            span,
+            r#"AvroSchema: `#[avro(alias = "..")]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")`"#

Review Comment:
   ```suggestion
               r#"AvroSchema: `#[avro(alias = "..")]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")]`"#
   ```



##########
avro_derive/src/enums/mod.rs:
##########
@@ -37,23 +45,224 @@ pub fn to_implementation(
             "AvroSchema: `#[serde(transparent)]` is only supported on structs",
         )]);
     }
-    if data
-        .variants
-        .iter()
-        .filter(|v| {
-            // Filter skipped variants, if the attributes fail to parse we'll 
also filter them out
-            // `plain` will throw proper errors for that.
-            VariantOptions::new(&v.attrs, v.span())
-                .map(|o| !o.skip)
-                .unwrap_or(false)
-        })
-        .all(|v| Fields::Unit == v.fields)
-    {
-        plain::to_implementation(input_span, ident, generics, container_attrs, 
data)
-    } else {
-        Err(vec![syn::Error::new(
+
+    match &container_attrs.repr {
+        None => {
+            if data
+                .variants
+                .iter()
+                .filter(|v| {
+                    // Filter skipped variants, if the attributes fail to 
parse we'll also filter them out
+                    // `plain` will throw proper errors for that.
+                    VariantOptions::new(&v.attrs, v.span())
+                        .map(|o| !o.skip)
+                        .unwrap_or(false)
+                })
+                .all(|v| Fields::Unit == v.fields)
+            {
+                plain::to_implementation(input_span, ident, generics, 
container_attrs, data)
+            } else {
+                union_of_records::to_implementation(ident, generics, 
container_attrs, data)
+            }
+        }
+        Some(Repr::Enum) => {
+            plain::to_implementation(input_span, ident, generics, 
container_attrs, data)
+        }
+        Some(Repr::BareUnion { .. }) => {
+            bare_union::to_implementation(ident, generics, container_attrs, 
data)
+        }
+        Some(Repr::UnionOfRecords) => {
+            union_of_records::to_implementation(ident, generics, 
container_attrs, data)
+        }
+        Some(Repr::RecordTagContent { .. }) => 
record_tag_content::to_implementation(
             input_span,
-            "AvroSchema: derive does not work for enums with non unit structs",
-        )])
+            ident,
+            generics,
+            container_attrs,
+            data,
+        ),
+        Some(Repr::RecordInternallyTagged { .. }) => {
+            record_internally_tagged::to_implementation(ident, generics, 
container_attrs, data)
+        }
+    }
+}
+
+fn newtype_extra_attribute_checks(
+    options: FieldOptions,
+    span: Span,
+) -> Result<FieldOptions, Vec<syn::Error>> {
+    let mut errors = Vec::new();
+    if options.doc.is_some() {
+        errors.push(syn::Error::new(
+            span,
+            r#"AvroSchema: `#[avro(doc = "..")]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")`"#
+        ));
+    }
+    if !matches!(options.default, FieldDefault::Trait) {
+        errors.push(syn::Error::new(
+            span,
+            r#"AvroSchema: `#[avro(default = ..)]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")`"#
+        ));
+    }
+    if !options.alias.is_empty() {
+        errors.push(syn::Error::new(
+            span,
+            r#"AvroSchema: `#[avro(alias = "..")]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")`"#
+        ));
     }
+    if options.rename.is_some() {
+        errors.push(syn::Error::new(
+            span,
+            r#"AvroSchema: `#[avro(rename = "..")]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")`"#

Review Comment:
   ```suggestion
               r#"AvroSchema: `#[avro(rename = "..")]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")]`"#
   ```



##########
avro_derive/tests/enum.rs:
##########
@@ -0,0 +1,764 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use apache_avro::reader::datum::GenericDatumReader;
+use apache_avro::writer::datum::GenericDatumWriter;
+use apache_avro::{AvroSchema, Schema};
+use pretty_assertions::assert_eq;
+use serde::{Deserialize, Serialize, de::DeserializeOwned};
+
+/// Takes in a type that implements the right combination of traits and runs 
it through a Serde Cycle and asserts the result is the same
+#[expect(
+    clippy::needless_pass_by_value,
+    reason = "Significantly complicates the trait bounds"
+)]
+#[track_caller]
+fn serde_assert<T>(obj: T)
+where
+    T: std::fmt::Debug + Serialize + DeserializeOwned + AvroSchema + PartialEq,
+{
+    assert_eq!(obj, serde(&obj));
+}
+
+#[track_caller]
+fn serde<T>(obj: &T) -> T
+where
+    T: Serialize + DeserializeOwned + AvroSchema,
+{
+    de(&ser(obj))
+}
+
+#[track_caller]
+fn ser<T>(obj: &T) -> Vec<u8>
+where
+    T: Serialize + AvroSchema,
+{
+    let schema = T::get_schema();
+    GenericDatumWriter::builder(&schema)
+        .build()
+        .unwrap()
+        .write_ser_to_vec(&obj)
+        .unwrap()
+}
+
+#[track_caller]
+fn de<T>(mut encoded: &[u8]) -> T
+where
+    T: DeserializeOwned + AvroSchema,
+{
+    assert!(!encoded.is_empty());
+    let schema = T::get_schema();
+    GenericDatumReader::builder(&schema)
+        .build()
+        .unwrap()
+        .read_deser(&mut encoded)
+        .unwrap()
+}
+
+#[test]
+fn avro_rs_561_bare_union_untagged_empty_tuple_variant() {
+    #[derive(Debug, Eq, PartialEq, AvroSchema, Serialize, Deserialize)]
+    #[avro(repr = "bare_union")]
+    #[serde(untagged)]
+    enum C {
+        A(),
+    }
+
+    serde_assert(C::A());
+}
+
+#[test]
+fn avro_rs_561_bare_union_empty_tuple_variant() {
+    #[derive(Debug, Eq, PartialEq, AvroSchema, Serialize, Deserialize)]
+    #[avro(repr = "bare_union")]
+    enum C {
+        A(),
+        B {},
+    }
+
+    serde_assert(C::A());
+    serde_assert(C::B {});
+}
+
+#[test]
+fn avro_rs_569_enum_repr_default() {
+    #[derive(AvroSchema, Debug, Serialize, Deserialize, Clone, PartialEq)]
+    enum Foo {
+        A,
+        B,
+        #[serde(rename = "D")]
+        C,
+    }
+
+    let schema = Schema::parse_str(
+        r#"{
+        "type": "enum",
+        "name": "Foo",
+        "symbols": ["A", "B", "D"]
+    }"#,
+    )
+    .unwrap();
+
+    assert_eq!(Foo::get_schema(), schema);
+    serde_assert(Foo::A);
+    serde_assert(Foo::B);
+    serde_assert(Foo::C);
+}
+
+#[test]
+fn avro_rs_569_enum_repr_enum() {
+    #[derive(AvroSchema, Debug, Serialize, Deserialize, Clone, PartialEq)]
+    #[avro(repr = "enum")]
+    enum Foo {
+        A,
+        B,
+        #[serde(rename = "D")]
+        C,
+    }
+
+    let schema = Schema::parse_str(
+        r#"{
+        "type": "enum",
+        "name": "Foo",
+        "symbols": ["A", "B", "D"]
+    }"#,
+    )
+    .unwrap();
+
+    assert_eq!(Foo::get_schema(), schema);
+    serde_assert(Foo::A);
+    serde_assert(Foo::B);
+    serde_assert(Foo::C);
+}
+
+#[test]
+fn avro_rs_569_enum_repr_record_tag_content_plain() {
+    #[derive(AvroSchema, Debug, Serialize, Deserialize, Clone, PartialEq)]
+    #[avro(repr = "record_tag_content")]
+    #[serde(tag = "type", content = "value")]
+    enum Foo {
+        A,
+        B,
+        #[serde(rename = "D")]
+        C,
+    }
+
+    let schema = Schema::parse_str(
+        r#"{
+        "type": "record",
+        "name": "Foo",
+        "fields": [
+            {
+                "name": "type",
+                "type": {
+                    "type": "enum",
+                    "name": "type",
+                    "symbols": ["A", "B", "D"]
+                }
+            },
+            {
+                "name": "value",
+                "type": [
+                    "null"
+                ]
+            }
+        ]
+    }"#,
+    )
+    .unwrap();
+
+    assert_eq!(Foo::get_schema(), schema);
+    serde_assert(Foo::A);
+    serde_assert(Foo::B);
+    serde_assert(Foo::C);
+}
+
+#[test]
+fn avro_rs_569_enum_repr_record_tag_content_tuple() {
+    #[derive(AvroSchema, Debug, Serialize, Deserialize, Clone, PartialEq)]
+    #[avro(repr = "record_tag_content")]
+    #[serde(tag = "type", content = "value")]
+    enum Foo {
+        A,
+        Alt {},
+        B(String),
+        #[serde(rename = "D")]
+        C(
+            String,
+            #[serde(rename = "is_it_true", alias = "is_it_false")] bool,
+        ),
+    }
+
+    let schema = Schema::parse_str(
+        r#"{
+        "type": "record",
+        "name": "Foo",
+        "fields": [
+            {
+                "name": "type",
+                "type": {
+                    "type": "enum",
+                    "name": "type",
+                    "symbols": ["A", "Alt", "B", "D"]
+                }
+            },
+            {
+                "name": "value",
+                "type": [
+                    "null",
+                    {
+                        "type": "record",
+                        "name": "Alt",
+                        "fields": [],
+                        "org.apache.avro.rust.tuple": true

Review Comment:
   Why is `Alt {}` marked as a tuple here ?



##########
avro_derive/src/enums/mod.rs:
##########
@@ -37,23 +45,224 @@ pub fn to_implementation(
             "AvroSchema: `#[serde(transparent)]` is only supported on structs",
         )]);
     }
-    if data
-        .variants
-        .iter()
-        .filter(|v| {
-            // Filter skipped variants, if the attributes fail to parse we'll 
also filter them out
-            // `plain` will throw proper errors for that.
-            VariantOptions::new(&v.attrs, v.span())
-                .map(|o| !o.skip)
-                .unwrap_or(false)
-        })
-        .all(|v| Fields::Unit == v.fields)
-    {
-        plain::to_implementation(input_span, ident, generics, container_attrs, 
data)
-    } else {
-        Err(vec![syn::Error::new(
+
+    match &container_attrs.repr {
+        None => {
+            if data
+                .variants
+                .iter()
+                .filter(|v| {
+                    // Filter skipped variants, if the attributes fail to 
parse we'll also filter them out
+                    // `plain` will throw proper errors for that.
+                    VariantOptions::new(&v.attrs, v.span())
+                        .map(|o| !o.skip)
+                        .unwrap_or(false)
+                })
+                .all(|v| Fields::Unit == v.fields)
+            {
+                plain::to_implementation(input_span, ident, generics, 
container_attrs, data)
+            } else {
+                union_of_records::to_implementation(ident, generics, 
container_attrs, data)
+            }
+        }
+        Some(Repr::Enum) => {
+            plain::to_implementation(input_span, ident, generics, 
container_attrs, data)
+        }
+        Some(Repr::BareUnion { .. }) => {
+            bare_union::to_implementation(ident, generics, container_attrs, 
data)
+        }
+        Some(Repr::UnionOfRecords) => {
+            union_of_records::to_implementation(ident, generics, 
container_attrs, data)
+        }
+        Some(Repr::RecordTagContent { .. }) => 
record_tag_content::to_implementation(
             input_span,
-            "AvroSchema: derive does not work for enums with non unit structs",
-        )])
+            ident,
+            generics,
+            container_attrs,
+            data,
+        ),
+        Some(Repr::RecordInternallyTagged { .. }) => {
+            record_internally_tagged::to_implementation(ident, generics, 
container_attrs, data)
+        }
+    }
+}
+
+fn newtype_extra_attribute_checks(
+    options: FieldOptions,
+    span: Span,
+) -> Result<FieldOptions, Vec<syn::Error>> {
+    let mut errors = Vec::new();
+    if options.doc.is_some() {
+        errors.push(syn::Error::new(
+            span,
+            r#"AvroSchema: `#[avro(doc = "..")]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")`"#
+        ));
+    }
+    if !matches!(options.default, FieldDefault::Trait) {
+        errors.push(syn::Error::new(
+            span,
+            r#"AvroSchema: `#[avro(default = ..)]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")`"#
+        ));
+    }
+    if !options.alias.is_empty() {
+        errors.push(syn::Error::new(
+            span,
+            r#"AvroSchema: `#[avro(alias = "..")]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")`"#
+        ));
     }
+    if options.rename.is_some() {
+        errors.push(syn::Error::new(
+            span,
+            r#"AvroSchema: `#[avro(rename = "..")]` only works on newtype 
variants when the enum uses `#[avro(repr = "union_of_records")`"#
+        ));
+    }
+    if options.flatten {
+        errors.push(syn::Error::new(
+            span,
+            r#"AvroSchema: `#[avro(flatten)]` only works on newtype variants 
when the enum uses `#[avro(repr = "union_of_records")`"#,

Review Comment:
   ```suggestion
               r#"AvroSchema: `#[avro(flatten)]` only works on newtype variants 
when the enum uses `#[avro(repr = "union_of_records")]`"#,
   ```



##########
avro_derive/src/attributes/mod.rs:
##########
@@ -24,14 +24,117 @@ use syn::{AttrStyle, Attribute, Expr, Ident, Path, 
spanned::Spanned};
 mod avro;
 mod serde;
 
+/// What `Schema` representation to generate for a type.
+#[derive(Debug, PartialEq)]
+pub enum Repr {
+    /// Generate a `Schema::Enum` for a `enum`.
+    ///
+    /// Only works for unit variants.
+    Enum,
+    /// Generate a `Schema::Union` for a `enum`.
+    ///
+    /// There can only be one unit variant and every newtype/struct/tuple 
variant must be unique.
+    BareUnion { untagged: bool },
+    /// Generate a `Schema::Union` with a `Schema::Record`  for a `enum`.
+    ///
+    /// This works for every enum as the records will have unique names for 
every variant.
+    UnionOfRecords,
+    /// Generate a `Schema::Record` with a tag and content field for a `enum`.
+    ///
+    /// Requires `#[serde(tag = "...", content = "...")]`.
+    RecordTagContent { tag: String, content: String },
+    /// Generate a `Schema::Record` with a tag field and flattened variant 
fields for a `enum`.
+    ///
+    /// Requires `#[serde(tag = "...")]`
+    RecordInternallyTagged { tag: String },
+}
+
+impl Repr {
+    fn from_avro_and_serde(
+        avro: Option<avro::Repr>,
+        tag: Option<String>,
+        content: Option<String>,
+        untagged: bool,
+        span: Span,
+    ) -> Result<Option<Self>, syn::Error> {
+        match avro {
+            Some(avro::Repr::Enum) => {
+                if tag.is_some() || content.is_some() || untagged {
+                    Err(syn::Error::new(
+                        span,
+                        r#"AvroSchema: `#[avro(repr = "enum")]` is 
incompatible with `#[serde(tag = "..")]`, `#[serde(content = "..")]`, and 
`#[serde(untagged)]`"#,
+                    ))
+                } else {
+                    Ok(Some(Self::Enum))
+                }
+            }
+            Some(avro::Repr::BareUnion) => {
+                if tag.is_some() || content.is_some() {
+                    Err(syn::Error::new(
+                        span,
+                        r#"AvroSchema: `#[avro(repr = "bare_union")]` is 
incompatible with `#[serde(tag = "..")]` and `#[serde(content = "..")]`"#,
+                    ))
+                } else {
+                    Ok(Some(Self::BareUnion { untagged }))
+                }
+            }
+            Some(avro::Repr::UnionOfRecords) => {
+                if tag.is_some() || content.is_some() || untagged {
+                    Err(syn::Error::new(
+                        span,
+                        r#"AvroSchema: `#[avro(repr = "union_of_records")]` is 
incompatible with `#[serde(tag = "..")]`, `#[serde(content = "..")]`, and 
`#[serde(untagged)]`"#,
+                    ))
+                } else {
+                    Ok(Some(Self::UnionOfRecords))
+                }
+            }
+            Some(avro::Repr::RecordTagContent) => {
+                if let Some(tag) = tag
+                    && let Some(content) = content
+                    && !untagged
+                {
+                    Ok(Some(Self::RecordTagContent { tag, content }))
+                } else {
+                    Err(syn::Error::new(
+                        span,
+                        r#"AvroSchema: `#[avro(repr = "record_tag_content")]` 
requires `#[serde(tag = "..", content = "..")]` and is incompatible with 
`#[serde(untagged)]`"#,
+                    ))
+                }
+            }
+            Some(avro::Repr::RecordInternallyTagged) => {
+                if let Some(tag) = tag
+                    && content.is_none()
+                    && !untagged
+                {
+                    Ok(Some(Self::RecordInternallyTagged { tag }))
+                } else {
+                    Err(syn::Error::new(
+                        span,
+                        r#"AvroSchema: `#[avro(repr = 
"record_internally_tagged")]` requires `#[serde(tag = "..")]` and is 
incompatible with `#[serde(content = "..")]` and `#[serde(untagged)]`"#,
+                    ))
+                }
+            }
+            None if tag.is_some() && content.is_some() => 
Ok(Some(Self::RecordTagContent {
+                tag: tag.unwrap(),
+                content: content.unwrap(),
+            })),
+            None if tag.is_some() => Ok(Some(Self::RecordInternallyTagged { 
tag: tag.unwrap() })),
+            None if untagged => Ok(Some(Self::BareUnion { untagged })),
+            None => Ok(None),

Review Comment:
   ```suggestion
               None => match (tag, content, untagged) {
                   (Some(tag), Some(content), false) => {
                       Ok(Some(Self::RecordTagContent { tag, content }))
                   }
                   (Some(tag), None, false) => {
                       Ok(Some(Self::RecordInternallyTagged { tag }))
                   }
                   (None, None, true) => Ok(Some(Self::BareUnion { untagged: 
true })),
                   (None, None, false) => Ok(None),
                   _ => Err(syn::Error::new(
                       span,
                       "AvroSchema: incompatible Serde tagging attributes",
                   )),
               }
   ```
   To prevent usage of incompatible Serde attributes.



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