Kriskras99 commented on code in PR #512:
URL: https://github.com/apache/avro-rs/pull/512#discussion_r3032068083
##########
avro/src/schema/union.rs:
##########
@@ -74,7 +81,116 @@ impl UnionSchema {
&self.schemas
}
- /// Returns true if the any of the variants of this `UnionSchema` is
`Null`.
+ /// Get the variant at the given index.
+ pub fn get_variant(&self, index: usize) -> Result<&Schema, Error> {
+ self.schemas.get(index).ok_or_else(|| {
+ Details::GetUnionVariant {
+ index: index as i64,
+ num_variants: self.schemas.len(),
+ }
+ .into()
+ })
+ }
+
+ /// Get the index of the provided [`SchemaKind`].
+ ///
+ /// The schema must not be a logical type, as only the base type are saved
in the lookup index.
+ pub(crate) fn index_of_schema_kind(&self, kind: SchemaKind) ->
Option<usize> {
+ self.variant_index.get(&kind).copied()
+ }
+
+ /// Get the index and schema for the provided name.
+ ///
+ /// Will use `names` to resolve references.
+ pub(crate) fn find_named_schema<'s>(
+ &'s self,
+ name: &str,
+ names: &'s HashMap<Name, impl Borrow<Schema>>,
+ ) -> Result<Option<(usize, &'s Schema)>, Error> {
+ for index in self.named_index.iter().copied() {
+ let schema = &self.schemas[index];
+ if let Some(schema_name) = schema.name()
+ && schema_name.name() == name
Review Comment:
No, it is used for matching Rust type names to schemas which don't include
the namespace. I've updated the documentation to make that more explicit.
--
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]