jklamer commented on a change in pull request #1602:
URL: https://github.com/apache/avro/pull/1602#discussion_r826442852
##########
File path: lang/rust/avro/src/schema.rs
##########
@@ -317,17 +328,73 @@ impl From<&str> for Name {
}
}
-impl Hash for Name {
- fn hash<H: Hasher>(&self, state: &mut H) {
- self.fullname(None).hash(state);
+pub struct ResolvedSchema<'s> {
+ names: HashMap<Name, &'s Schema>,
+ schema: &'s Schema,
+}
+
+impl<'s> From<&'s Schema> for ResolvedSchema<'s> {
+ fn from(schema: &'s Schema) -> Self {
+ let names = HashMap::new();
+ let mut rs = ResolvedSchema { names, schema };
+ Self::from_internal(rs.schema, &mut rs.names, &None);
+ rs
}
}
-impl Eq for Name {}
+impl<'s> ResolvedSchema<'s> {
+ pub fn get_names(&self) -> &HashMap<Name, &'s Schema> {
+ &self.names
+ }
-impl PartialEq for Name {
- fn eq(&self, other: &Name) -> bool {
- self.fullname(None).eq(&other.fullname(None))
+ pub fn get_schema(&self) -> &Schema {
+ self.schema
+ }
+
+ fn from_internal(
+ schema: &'s Schema,
+ idx: &mut HashMap<Name, &'s Schema>,
+ enclosing_namespace: &Namespace,
+ ) {
+ match schema {
+ Schema::Array(schema) | Schema::Map(schema) => {
+ Self::from_internal(schema, idx, enclosing_namespace)
+ }
+ Schema::Union(UnionSchema { schemas, .. }) => {
+ for schema in schemas {
+ Self::from_internal(schema, idx, enclosing_namespace)
+ }
+ }
+ Schema::Enum { name, .. } | Schema::Fixed { name, .. } => {
+ let fully_qualified_name =
name.fully_qualified_name(enclosing_namespace);
+ if idx.insert(fully_qualified_name.clone(), schema).is_some() {
+ panic!(
Review comment:
Will do. And I believe we will want to do it for the encoding workflow
as well.
--
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]