Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Child NodePath's #112

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions zarrs/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,51 @@
})
.collect()
}

/// Return the paths of the groups children
///
/// # Errors
/// Returns [`StorageError`] if there is an underlying error with the store.
pub fn child_paths(&self, recursive: bool) -> Result<Vec<NodePath>, StorageError> {
let paths = self
.children(recursive)?
.into_iter()
.map(Into::into)
.collect();
Ok(paths)
}

Check warning on line 301 in zarrs/src/group.rs

View check run for this annotation

Codecov / codecov/patch

zarrs/src/group.rs#L294-L301

Added lines #L294 - L301 were not covered by tests

/// 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<Vec<NodePath>, 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)
}

Check warning on line 317 in zarrs/src/group.rs

View check run for this annotation

Codecov / codecov/patch

zarrs/src/group.rs#L307-L317

Added lines #L307 - L317 were not covered by tests

/// 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<Vec<NodePath>, 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)
}

Check warning on line 333 in zarrs/src/group.rs

View check run for this annotation

Codecov / codecov/patch

zarrs/src/group.rs#L323-L333

Added lines #L323 - L333 were not covered by tests
}

#[cfg(feature = "async")]
Expand Down
6 changes: 6 additions & 0 deletions zarrs/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
}
}

impl From<Node> for NodePath {
fn from(value: Node) -> Self {
value.path
}

Check warning on line 73 in zarrs/src/node.rs

View check run for this annotation

Codecov / codecov/patch

zarrs/src/node.rs#L71-L73

Added lines #L71 - L73 were not covered by tests
}

/// A node creation error.
#[derive(Debug, Error)]
pub enum NodeCreateError {
Expand Down
Loading