This is an automated email from the ASF dual-hosted git repository.

kriskras99 pushed a commit to branch feat/resolve_prep
in repository https://gitbox.apache.org/repos/asf/avro-rs.git

commit 3d71ce5f47da8c349797170a725695e57bd9fcf2
Author: Kriskras99 <[email protected]>
AuthorDate: Mon Jan 26 23:01:23 2026 +0100

    feat: Improve `Resolved(Owned)Schema` API and documentation
---
 avro/src/schema/resolve.rs | 82 ++++++++++++++++++++++++++--------------------
 1 file changed, 47 insertions(+), 35 deletions(-)

diff --git a/avro/src/schema/resolve.rs b/avro/src/schema/resolve.rs
index 90bdea3..9882d7b 100644
--- a/avro/src/schema/resolve.rs
+++ b/avro/src/schema/resolve.rs
@@ -13,42 +13,35 @@ pub struct ResolvedSchema<'s> {
     schemata: Vec<&'s Schema>,
 }
 
-impl<'s> TryFrom<&'s Schema> for ResolvedSchema<'s> {
-    type Error = Error;
+impl<'s> ResolvedSchema<'s> {
+    pub fn get_schemata(&self) -> Vec<&'s Schema> {
+        self.schemata.clone()
+    }
 
-    fn try_from(schema: &'s Schema) -> AvroResult<Self> {
-        let names = HashMap::new();
-        let mut rs = ResolvedSchema {
-            names_ref: names,
-            schemata: vec![schema],
-        };
-        rs.resolve(rs.get_schemata(), &None, None)?;
-        Ok(rs)
+    pub fn get_names(&self) -> &NamesRef<'s> {
+        &self.names_ref
     }
-}
 
-impl<'s> TryFrom<Vec<&'s Schema>> for ResolvedSchema<'s> {
-    type Error = Error;
+    /// Resolve all references in this schema.
+    ///
+    /// If some references are to other schemas, see 
[`ResolvedSchema::new_with_schemata`].
+    pub fn new(schema: &'s Schema) -> AvroResult<Self> {
+        Self::new_with_schemata(vec![schema])
+    }
 
-    fn try_from(schemata: Vec<&'s Schema>) -> AvroResult<Self> {
-        let names = HashMap::new();
+    /// Resolve all references in these schemas.
+    ///
+    // TODO: Support this
+    /// These schemas will be resolved in order, so references to schemas 
later in the
+    /// list is not supported.
+    pub fn new_with_schemata(schemata: Vec<&'s Schema>) -> AvroResult<Self> {
         let mut rs = ResolvedSchema {
-            names_ref: names,
+            names_ref: HashMap::new(),
             schemata,
         };
         rs.resolve(rs.get_schemata(), &None, None)?;
         Ok(rs)
     }
-}
-
-impl<'s> ResolvedSchema<'s> {
-    pub fn get_schemata(&self) -> Vec<&'s Schema> {
-        self.schemata.clone()
-    }
-
-    pub fn get_names(&self) -> &NamesRef<'s> {
-        &self.names_ref
-    }
 
     /// Creates `ResolvedSchema` with some already known schemas.
     ///
@@ -138,26 +131,37 @@ impl<'s> ResolvedSchema<'s> {
     }
 }
 
+impl<'s> TryFrom<&'s Schema> for ResolvedSchema<'s> {
+    type Error = Error;
+
+    fn try_from(schema: &'s Schema) -> AvroResult<Self> {
+        Self::new(schema)
+    }
+}
+
+impl<'s> TryFrom<Vec<&'s Schema>> for ResolvedSchema<'s> {
+    type Error = Error;
+
+    fn try_from(schemata: Vec<&'s Schema>) -> AvroResult<Self> {
+        Self::new_with_schemata(schemata)
+    }
+}
+
 pub struct ResolvedOwnedSchema {
     names: Names,
     root_schema: Schema,
 }
 
-impl TryFrom<Schema> for ResolvedOwnedSchema {
-    type Error = Error;
-
-    fn try_from(schema: Schema) -> AvroResult<Self> {
-        let names = HashMap::new();
+impl ResolvedOwnedSchema {
+    pub fn new(root_schema: Schema) -> AvroResult<Self> {
         let mut rs = ResolvedOwnedSchema {
-            names,
-            root_schema: schema,
+            names: HashMap::new(),
+            root_schema,
         };
         resolve_names(&rs.root_schema, &mut rs.names, &None)?;
         Ok(rs)
     }
-}
 
-impl ResolvedOwnedSchema {
     pub fn get_root_schema(&self) -> &Schema {
         &self.root_schema
     }
@@ -166,6 +170,14 @@ impl ResolvedOwnedSchema {
     }
 }
 
+impl TryFrom<Schema> for ResolvedOwnedSchema {
+    type Error = Error;
+
+    fn try_from(schema: Schema) -> AvroResult<Self> {
+        Self::new(schema)
+    }
+}
+
 pub fn resolve_names(
     schema: &Schema,
     names: &mut Names,

Reply via email to