You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Aaron Spiegel (Jira)" <ji...@apache.org> on 2022/11/10 14:28:00 UTC
[jira] [Created] (AVRO-3668) Rust AvroSchema derive should support non-unit enums
Aaron Spiegel created AVRO-3668:
-----------------------------------
Summary: Rust AvroSchema derive should support non-unit enums
Key: AVRO-3668
URL: https://issues.apache.org/jira/browse/AVRO-3668
Project: Apache Avro
Issue Type: New Feature
Components: rust
Reporter: Aaron Spiegel
The idiomatic way to create type unions in Rust is to create a non-unit Enum with unnamed fields. As a user, I would like to derive an Avro schema from this type of object:
{code:java}
#[derive(AvroSchema)]
enum MyEnum {
AsAString(String),
AsAnInt(i32),
}
#[derive(AvroSchema)]
struct MyStuct {
my_enum: MyEnum,
}{code}
Which would create a schema of:
{code:java}
{
"name" : "my_struct",
"type" : "record",
"fields" :
[
{
"name" : "my_enum",
"type" : [
"string",
"int"
]
}
]
}{code}
Rust also supports named fields for structure types:
{code:java}
#[derive(AvroSchema)]
enum MyEnum {
NamedField: {
value: String,
count: i32,
}
}
#[derive(AvroSchema)]
struct MyStuct {
my_enum: MyEnum,
} {code}
The Rust enum also supports named fields to represent embedded structs, and enums with a mix of unit fields, named, and unnamed fields. I would consider these variants outside the scope of this issue, though they may also be supported by the AvroSchema derive with embedded records simlar to the approach describe in AVRO-3646
--
This message was sent by Atlassian Jira
(v8.20.10#820010)