From c4f22416a3022c0665fd727fe8ee40ba9cae08dc Mon Sep 17 00:00:00 2001 From: niklasmueboe Date: Wed, 25 Dec 2024 14:19:11 +0100 Subject: [PATCH] get child paths from group --- zarrs/src/group.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ zarrs/src/node.rs | 6 ++++++ 2 files changed, 51 insertions(+) diff --git a/zarrs/src/group.rs b/zarrs/src/group.rs index 3d2065c7..c1bd3a09 100644 --- a/zarrs/src/group.rs +++ b/zarrs/src/group.rs @@ -286,6 +286,51 @@ impl Group Result, StorageError> { + let paths = self + .children(recursive)? + .into_iter() + .map(Into::into) + .collect(); + Ok(paths) + } + + /// Return the paths of the groups children if the child is a group + /// + /// # Errors + /// Returns [`StorageError`] if there is an underlying error with the store. + pub fn child_group_paths(&self, recursive: bool) -> Result, StorageError> { + let paths = self + .children(recursive)? + .into_iter() + .filter_map(|node| match node.metadata() { + NodeMetadata::Group(_) => Some(node.into()), + NodeMetadata::Array(_) => None, + }) + .collect(); + Ok(paths) + } + + /// Return the paths of the groups children if the child is an array + /// + /// # Errors + /// Returns [`StorageError`] if there is an underlying error with the store. + pub fn child_array_paths(&self, recursive: bool) -> Result, StorageError> { + let paths = self + .children(recursive)? + .into_iter() + .filter_map(|node| match node.metadata() { + NodeMetadata::Array(_) => Some(node.into()), + NodeMetadata::Group(_) => None, + }) + .collect(); + Ok(paths) + } } #[cfg(feature = "async")] diff --git a/zarrs/src/node.rs b/zarrs/src/node.rs index 43f0f246..d4b02a6b 100644 --- a/zarrs/src/node.rs +++ b/zarrs/src/node.rs @@ -67,6 +67,12 @@ impl From for NodeMetadata { } } +impl From for NodePath { + fn from(value: Node) -> Self { + value.path + } +} + /// A node creation error. #[derive(Debug, Error)] pub enum NodeCreateError {