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

Refactor GroupMetadata{V3,V2} constructors #96

Merged
merged 1 commit into from
Nov 10, 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
12 changes: 8 additions & 4 deletions zarrs_metadata/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Changed
- **Breaking**: Mark `GroupMetadataV3` and `ArrayMetadataV3` as non-exhaustive
- **Breaking**: Bump MSRV to 1.77 (21 March, 2024)
- **Breaking**: Mark `GroupMetadataV3` and `ArrayMetadataV3` as non-exhaustive
- **Breaking**: Bump MSRV to 1.77 (21 March, 2024)
- Refactor `GroupMetadata{V3,V2}` constructors
- **Breaking**: `GroupMetadataV3::new()` is now parameter free
- Add `GroupMetadataV2::new()`
- Add `GroupMetadata{V3,V2}::with_{attributes,additional_fields}()`

## [0.1.0] - 2024-09-02

### Added
- Initial release
- Split from the `metadata` module of `zarrs` 0.17.0-dev
- Initial release
- Split from the `metadata` module of `zarrs` 0.17.0-dev

[unreleased]: https://github.com/LDeakin/zarrs/compare/zarrs_metadata-v0.1.0...HEAD
[0.1.0]: https://github.com/LDeakin/zarrs/releases/tag/zarrs_metadata-v0.1.0
35 changes: 35 additions & 0 deletions zarrs_metadata/src/v2/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,38 @@
#[serde(default, flatten)]
pub additional_fields: AdditionalFields,
}

impl Default for GroupMetadataV2 {
fn default() -> Self {
Self::new()
}

Check warning on line 25 in zarrs_metadata/src/v2/group.rs

View check run for this annotation

Codecov / codecov/patch

zarrs_metadata/src/v2/group.rs#L23-L25

Added lines #L23 - L25 were not covered by tests
}

impl GroupMetadataV2 {
/// Create Zarr V2 group metadata.
#[must_use]
pub fn new() -> Self {
Self {
zarr_format: monostate::MustBe!(2u64),
attributes: serde_json::Map::new(),
additional_fields: AdditionalFields::default(),
}
}

Check warning on line 37 in zarrs_metadata/src/v2/group.rs

View check run for this annotation

Codecov / codecov/patch

zarrs_metadata/src/v2/group.rs#L31-L37

Added lines #L31 - L37 were not covered by tests

/// Set the user attributes.
#[must_use]
pub fn with_attributes(
mut self,
attributes: serde_json::Map<String, serde_json::Value>,
) -> Self {
self.attributes = attributes;
self
}

Check warning on line 47 in zarrs_metadata/src/v2/group.rs

View check run for this annotation

Codecov / codecov/patch

zarrs_metadata/src/v2/group.rs#L41-L47

Added lines #L41 - L47 were not covered by tests

/// Set the additional fields.
#[must_use]
pub fn with_additional_fields(mut self, additional_fields: AdditionalFields) -> Self {
self.additional_fields = additional_fields;
self
}

Check warning on line 54 in zarrs_metadata/src/v2/group.rs

View check run for this annotation

Codecov / codecov/patch

zarrs_metadata/src/v2/group.rs#L51-L54

Added lines #L51 - L54 were not covered by tests
}
7 changes: 3 additions & 4 deletions zarrs_metadata/src/v2_to_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@
#[allow(clippy::too_many_lines)]
#[must_use]
pub fn group_metadata_v2_to_v3(group_metadata_v2: &GroupMetadataV2) -> GroupMetadataV3 {
GroupMetadataV3::new(
group_metadata_v2.attributes.clone(),
group_metadata_v2.additional_fields.clone(),
)
GroupMetadataV3::new()
.with_attributes(group_metadata_v2.attributes.clone())
.with_additional_fields(group_metadata_v2.additional_fields.clone())

Check warning on line 38 in zarrs_metadata/src/v2_to_v3.rs

View check run for this annotation

Codecov / codecov/patch

zarrs_metadata/src/v2_to_v3.rs#L36-L38

Added lines #L36 - L38 were not covered by tests
}

/// An error conerting Zarr V3 array metadata to V3.
Expand Down
30 changes: 22 additions & 8 deletions zarrs_metadata/src/v3/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,36 @@

impl Default for GroupMetadataV3 {
fn default() -> Self {
Self::new(serde_json::Map::new(), AdditionalFields::default())
Self::new()
}
}

impl GroupMetadataV3 {
/// Create group metadata.
/// Create Zarr V3 group metadata.
#[must_use]
pub fn new(
attributes: serde_json::Map<String, serde_json::Value>,
additional_fields: AdditionalFields,
) -> Self {
pub fn new() -> Self {
Self {
zarr_format: monostate::MustBe!(3u64),
node_type: monostate::MustBe!("group"),
attributes,
additional_fields,
attributes: serde_json::Map::new(),
additional_fields: AdditionalFields::default(),
}
}

/// Set the user attributes.
#[must_use]
pub fn with_attributes(
mut self,
attributes: serde_json::Map<String, serde_json::Value>,
) -> Self {
self.attributes = attributes;
self
}

Check warning on line 62 in zarrs_metadata/src/v3/group.rs

View check run for this annotation

Codecov / codecov/patch

zarrs_metadata/src/v3/group.rs#L56-L62

Added lines #L56 - L62 were not covered by tests

/// Set the additional fields.
#[must_use]
pub fn with_additional_fields(mut self, additional_fields: AdditionalFields) -> Self {
self.additional_fields = additional_fields;
self
}

Check warning on line 69 in zarrs_metadata/src/v3/group.rs

View check run for this annotation

Codecov / codecov/patch

zarrs_metadata/src/v3/group.rs#L66-L69

Added lines #L66 - L69 were not covered by tests
}