Skip to content

Commit

Permalink
Merge pull request #13 from lorenzocerrone/add_node_getters
Browse files Browse the repository at this point in the history
- Implement getters for Node path, children, and metadata
- Derive clone for Node and NodeMetadata
- Update changelog

Fixes #12
  • Loading branch information
LDeakin authored Feb 21, 2024
2 parents ef43dbb + 61e41ab commit d0da392
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add more tests for `Array`, codecs, store locks, and more
- Add `array_write_read_ndarray` example
- Add `array::bytes_to_ndarray()` and make `array::elements_to_ndarray()` public
- [#13](https://github.com/LDeakin/zarrs/pull/13) Add `node::Node::path()`, `metadata()`, and `children()` by [@lorenzocerrone]
- [#13](https://github.com/LDeakin/zarrs/pull/13) Derive `Clone` for `node::Node` and `node::NodeMetadata` by [@lorenzocerrone]

### Changed
#### Arrays
Expand Down
20 changes: 19 additions & 1 deletion src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::storage::{
/// A Zarr hierarchy node.
///
/// See <https://zarr-specs.readthedocs.io/en/latest/v3/core/v3.0.html#hierarchy>.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Node {
/// Node path.
path: NodePath,
Expand Down Expand Up @@ -141,6 +141,24 @@ impl Node {
unsafe { NodeName::new_unchecked(name) }
}

/// Returns a reference to the path of the node.
#[must_use]
pub fn path(&self) -> &NodePath {
&self.path
}

/// Returns a reference to the metadata of the node.
#[must_use]
pub fn metadata(&self) -> &NodeMetadata {
&self.metadata
}

/// Returns a reference to the children of the node.
#[must_use]
pub fn children(&self) -> &[Node] {
&self.children
}

/// Return a tree representation of a hierarchy as a string.
///
/// Arrays are annotated with their shape and data type.
Expand Down
2 changes: 1 addition & 1 deletion src/node/node_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{array::ArrayMetadata, group::GroupMetadata};

/// Node metadata ([`ArrayMetadata`] or [`GroupMetadata`]).
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
#[serde(untagged)]
pub enum NodeMetadata {
/// Array metadata.
Expand Down

0 comments on commit d0da392

Please sign in to comment.