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

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new e96e6091b3 Add `VariantPath::is_empty` (#8791)
e96e6091b3 is described below

commit e96e6091b3b70e55b124bae041e0ce73da2c7f45
Author: Matthew Kim <[email protected]>
AuthorDate: Thu Nov 6 06:00:48 2025 -0500

    Add `VariantPath::is_empty` (#8791)
    
    # Rationale for this change
    
    This PR adds `VariantPath::is_empty` which checks whether `VariantPath`
    contains an empty list of `VariantPathElement`s.
    
    I found this API to be helpful when validating a `VariantPath`, since a
    `VariantPath` is only meaningful if it holds a nonempty list of
    `VariantPathElement`s
---
 parquet-variant/src/path.rs | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/parquet-variant/src/path.rs b/parquet-variant/src/path.rs
index 794636ef40..6ca68dc7c1 100644
--- a/parquet-variant/src/path.rs
+++ b/parquet-variant/src/path.rs
@@ -87,6 +87,11 @@ impl<'a> VariantPath<'a> {
     pub fn push(&mut self, element: impl Into<VariantPathElement<'a>>) {
         self.0.push(element.into());
     }
+
+    /// Returns whether [`VariantPath`] has no path elements
+    pub fn is_empty(&self) -> bool {
+        self.0.is_empty()
+    }
 }
 
 impl<'a> From<Vec<VariantPathElement<'a>>> for VariantPath<'a> {
@@ -182,3 +187,21 @@ impl<'a> From<usize> for VariantPathElement<'a> {
         VariantPathElement::index(index)
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[test]
+    fn test_variant_path_empty() {
+        let path = VariantPath::from_iter([]);
+        assert!(path.is_empty());
+    }
+
+    #[test]
+    fn test_variant_path_non_empty() {
+        let p = VariantPathElement::from("a");
+        let path = VariantPath::from_iter([p]);
+        assert!(!path.is_empty());
+    }
+}

Reply via email to