Skip to content

Commit

Permalink
Implement Deserialize for DataType
Browse files Browse the repository at this point in the history
  • Loading branch information
LDeakin committed Feb 28, 2024
1 parent f7be32d commit aafd3f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Implement `Deserialize` for `DataType`
- A convenience for `zarrs` consumers. `ArrayMetadata` continues to use `Metadata` to parse unknown data types.

## [0.12.2] - 2024-02-26

### Added
Expand Down
8 changes: 8 additions & 0 deletions src/array/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use derive_more::From;
use half::{bf16, f16};
use serde::de::Error;
use thiserror::Error;

use crate::{
Expand Down Expand Up @@ -72,6 +73,13 @@ impl PartialEq for DataType {

impl Eq for DataType {}

impl<'de> serde::Deserialize<'de> for DataType {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let metadata = Metadata::deserialize(d)?;
DataType::from_metadata(&metadata).map_err(|err| D::Error::custom(err.to_string()))
}
}

// /// A data type plugin.
// pub type DataTypePlugin = Plugin<Box<dyn DataTypeExtension>>;
// inventory::collect!(DataTypePlugin);
Expand Down

0 comments on commit aafd3f7

Please sign in to comment.