[
https://issues.apache.org/jira/browse/AVRO-3759?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17724286#comment-17724286
]
Fedor Telnov commented on AVRO-3759:
------------------------------------
Let's say you want your function to receive record schema as an argument. How
would you do it currently? You'll use Schema as an input argument and simply
match on it, returning error if schema is not Record. Not very convenient,
isn't it?
With such a feature, we can easily store RecordSchema as is - and require it as
an argument or anything else. It would reduce the amount of matches we need to
write. Currently we must write our replacements for Record(and introduce
TryFrom trait impls, for example), which is painful.
Generally speaking, it is well-known Rust pattern. Rust type system does not
allow us to use enums variants as types, so we came up with an idea I
introduced previously. Related issue:
https://github.com/rust-lang/lang-team/issues/122
> [Rust] Schema types inconsistency
> ---------------------------------
>
> Key: AVRO-3759
> URL: https://issues.apache.org/jira/browse/AVRO-3759
> Project: Apache Avro
> Issue Type: Improvement
> Components: rust
> Reporter: Fedor Telnov
> Priority: Major
>
> That is how Unions and Records are defined in apache-avro Rust crate:
>
> ```
> /// A `union` Avro schema.
> Union(UnionSchema),
> /// A `record` Avro schema.
> ///
> /// The `lookup` table maps field names to their position in the `Vec`
> /// of `fields`.
> Record {
> name: Name,
> aliases: Aliases,
> doc: Documentation,
> fields: Vec<RecordField>,
> lookup: BTreeMap<String, usize>,
> },
> ```
>
> That is inconsistent - one variant is defined with pattern Type(Type) which
> is VERY convenient(for instance, it allows one to use UnionSchema as type),
> and the other one(Record) is simply a struct variant, which is not very
> convenient. My proposition is to hide Record's body in RecordSchema type and
> use it here - just as you do with union. That would significantly help users,
> as we can't use enum variants as types in Rust. It can also be done with
> other schema types as well.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)