Skip to content

Commit

Permalink
FillValueMetadata::try_as_uint/int from uint/int
Browse files Browse the repository at this point in the history
  • Loading branch information
LDeakin committed Oct 9, 2023
1 parent b6a06b8 commit e23a7cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- `FillValueMetadata::try_as_uint/int` can both now handle `FillValueMetadata::Uint/Int`

## [0.5.0] - 2023-10-08

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zarrs"
description = "A library for the Zarr V3 storage format for multidimensional arrays and metadata"
version = "0.5.0"
version = "0.5.1"
authors = ["Lachlan Deakin <ljdgit@gmail.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down
18 changes: 12 additions & 6 deletions src/array/fill_value_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum FillValueMetadata {
/// A boolean value.
Bool(bool),
/// An unsigned integer.
Uint(u64),
Uint(u64), // FIXME: UInt for consistency?
/// A signed integer.
Int(i64),
/// A float.
Expand Down Expand Up @@ -132,25 +132,31 @@ impl FillValueMetadata {
}
}

/// Convert the fill value an int.
/// Convert the fill value to int.
#[must_use]
pub fn try_as_int<T: std::convert::TryFrom<i64>>(&self) -> Option<T> {
pub fn try_as_int<T: std::convert::TryFrom<i64> + std::convert::TryFrom<u64>>(
&self,
) -> Option<T> {
match self {
FillValueMetadata::Int(int) => T::try_from(*int).ok(),
FillValueMetadata::Uint(uint) => T::try_from(*uint).ok(),
_ => None,
}
}

/// Convert the fill value a uint.
/// Convert the fill value to uint.
#[must_use]
pub fn try_as_uint<T: std::convert::TryFrom<u64>>(&self) -> Option<T> {
pub fn try_as_uint<T: std::convert::TryFrom<i64> + std::convert::TryFrom<u64>>(
&self,
) -> Option<T> {
match self {
FillValueMetadata::Int(int) => T::try_from(*int).ok(),
FillValueMetadata::Uint(uint) => T::try_from(*uint).ok(),
_ => None,
}
}

/// Convert the fill value a float.
/// Convert the fill value to float.
#[must_use]
pub fn try_as_float<T: FloatCore>(&self) -> Option<T> {
match self {
Expand Down

0 comments on commit e23a7cf

Please sign in to comment.