Kriskras99 commented on code in PR #493:
URL: https://github.com/apache/avro-rs/pull/493#discussion_r2877451717


##########
avro/src/schema/name.rs:
##########
@@ -126,22 +149,39 @@ impl Name {
     /// ```
     /// # use apache_avro::{Error, schema::Name};
     /// assert_eq!(
-    ///     
Name::new("some_name")?.fully_qualified_name(&Some("some_namespace".into())),
+    ///     
Name::new("some_name")?.fully_qualified_name(Some("some_namespace")).into_owned(),
     ///     Name::new("some_namespace.some_name")?
     /// );
     /// assert_eq!(
-    ///     
Name::new("some_namespace.some_name")?.fully_qualified_name(&Some("other_namespace".into())),
+    ///     
Name::new("some_namespace.some_name")?.fully_qualified_name(Some("other_namespace")).into_owned(),
     ///     Name::new("some_namespace.some_name")?
     /// );
     /// # Ok::<(), Error>(())
     /// ```
-    pub fn fully_qualified_name(&self, enclosing_namespace: &Namespace) -> 
Name {
-        Name {
-            name: self.name.clone(),
-            namespace: self
-                .namespace
-                .clone()
-                .or_else(|| enclosing_namespace.clone().filter(|ns| 
!ns.is_empty())),
+    pub fn fully_qualified_name(&self, enclosing_namespace: NamespaceRef) -> 
Cow<'_, Name> {
+        if self.index_of_name == 0
+            && let Some(namespace) = enclosing_namespace
+            && !namespace.is_empty()
+        {
+            Cow::Owned(Self {
+                namespace_and_name: format!("{namespace}.{}", 
self.namespace_and_name),
+                index_of_name: namespace.len() + 1,
+            })
+        } else {
+            Cow::Borrowed(self)
+        }
+    }
+
+    /// Create an empty name.
+    ///
+    /// This name is invalid and should never be used anywhere! The only valid 
use is filling
+    /// a `Name` field that will not be used.
+    ///
+    /// Using this name will cause a panic.
+    pub(crate) fn invalid_empty_name() -> Self {
+        Self {
+            namespace_and_name: String::new(),

Review Comment:
   Instead of this, I modified the `Debug` implementation to show `Name(Invalid 
name!)` instead. I also made `Display` panic when an invalid name is used.
   As users cannot create this type, this panic should never happen.



-- 
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]

Reply via email to