pub trait DataTypeTraits:
ExtensionName
+ Debug
+ Send
+ Sync {
// Required methods
fn configuration(&self, version: ZarrVersion) -> Configuration;
fn size(&self) -> DataTypeSize;
fn fill_value(
&self,
fill_value_metadata: &FillValueMetadataV3,
version: ZarrVersion,
) -> Result<FillValue, DataTypeFillValueMetadataError>;
fn metadata_fill_value(
&self,
fill_value: &FillValue,
) -> Result<FillValueMetadataV3, DataTypeFillValueError>;
fn as_any(&self) -> &(dyn Any + 'static);
// Provided methods
fn configuration_v3(&self) -> Configuration { ... }
fn configuration_v2(&self) -> Configuration { ... }
fn fill_value_v2(
&self,
fill_value_metadata: &FillValueMetadataV3,
) -> Result<FillValue, DataTypeFillValueMetadataError> { ... }
fn fill_value_v3(
&self,
fill_value_metadata: &FillValueMetadataV3,
) -> Result<FillValue, DataTypeFillValueMetadataError> { ... }
fn eq(&self, other: &dyn DataTypeTraits) -> bool { ... }
fn compatible_element_types(&self) -> &'static [TypeId] { ... }
}Expand description
Traits for a data type extension.
The in-memory size of a data type can differ between its associated Rust structure and the serialised ArrayBytes passed into the codec pipeline.
For example, a Rust struct that has padding bytes can be converted to tightly packed bytes before it is passed into the codec pipeline for encoding, and vice versa for decoding.
It is recommended to define a concrete structure representing a single element of a custom data type that implements Element and ElementOwned.
These traits have into_array_bytes and from_array_bytes methods for this purpose that enable custom data types to be used with the Array::{store,retrieve}_*_elements variants.
These methods should encode data to and from native endianness if endianness is applicable, unless the endianness should be explicitly fixed.
Note that codecs that act on numerical data typically expect the data to be in native endianness.
A custom data type must also directly handle conversion of fill value metadata to fill value bytes, and vice versa.
Required Methods§
Sourcefn configuration(&self, version: ZarrVersion) -> Configuration
fn configuration(&self, version: ZarrVersion) -> Configuration
The configuration of the data type.
Sourcefn size(&self) -> DataTypeSize
fn size(&self) -> DataTypeSize
The size of the data type.
This size may differ from the size in memory of the data type.
It represents the size of elements passing through array to array and array to bytes codecs in the codec pipeline (i.e., after conversion to ArrayBytes).
Sourcefn fill_value(
&self,
fill_value_metadata: &FillValueMetadataV3,
version: ZarrVersion,
) -> Result<FillValue, DataTypeFillValueMetadataError>
fn fill_value( &self, fill_value_metadata: &FillValueMetadataV3, version: ZarrVersion, ) -> Result<FillValue, DataTypeFillValueMetadataError>
Create a fill value from metadata.
§Errors
Returns DataTypeFillValueMetadataError if the fill value is incompatible with the data type.
Sourcefn metadata_fill_value(
&self,
fill_value: &FillValue,
) -> Result<FillValueMetadataV3, DataTypeFillValueError>
fn metadata_fill_value( &self, fill_value: &FillValue, ) -> Result<FillValueMetadataV3, DataTypeFillValueError>
Create fill value metadata.
§Errors
Returns an DataTypeFillValueError if the metadata cannot be created from the fill value.
Provided Methods§
Sourcefn configuration_v3(&self) -> Configuration
fn configuration_v3(&self) -> Configuration
The Zarr V3 configuration of the data type.
Sourcefn configuration_v2(&self) -> Configuration
fn configuration_v2(&self) -> Configuration
The Zarr V2 configuration of the data type.
Sourcefn fill_value_v2(
&self,
fill_value_metadata: &FillValueMetadataV3,
) -> Result<FillValue, DataTypeFillValueMetadataError>
fn fill_value_v2( &self, fill_value_metadata: &FillValueMetadataV3, ) -> Result<FillValue, DataTypeFillValueMetadataError>
Create a fill value from Zarr V2 metadata.
§Errors
Returns DataTypeFillValueMetadataError if the fill value is incompatible with the data type.
Sourcefn fill_value_v3(
&self,
fill_value_metadata: &FillValueMetadataV3,
) -> Result<FillValue, DataTypeFillValueMetadataError>
fn fill_value_v3( &self, fill_value_metadata: &FillValueMetadataV3, ) -> Result<FillValue, DataTypeFillValueMetadataError>
Create a fill value from Zarr V3 metadata.
§Errors
Returns DataTypeFillValueMetadataError if the fill value is incompatible with the data type.
Sourcefn eq(&self, other: &dyn DataTypeTraits) -> bool
fn eq(&self, other: &dyn DataTypeTraits) -> bool
Compare this data type with another for equality.
The default implementation compares type via TypeId and configuration.
Custom data types may override this for more efficient comparison.
Sourcefn compatible_element_types(&self) -> &'static [TypeId]
fn compatible_element_types(&self) -> &'static [TypeId]
Returns the set of Rust element types this data type is compatible with.
Element implementations use this to check compatibility without needing to know about every specific data type.
Custom data types can override this to declare compatibility with existing Element implementations.
Returns an empty slice by default (no automatic compatibility).
Implementors§
impl DataTypeTraits for BFloat16DataType
impl DataTypeTraits for BoolDataType
impl DataTypeTraits for BytesDataType
impl DataTypeTraits for Complex64DataType
impl DataTypeTraits for Complex128DataType
impl DataTypeTraits for ComplexBFloat16DataType
impl DataTypeTraits for ComplexFloat4E2M1FNDataType
impl DataTypeTraits for ComplexFloat6E2M3FNDataType
impl DataTypeTraits for ComplexFloat6E3M2FNDataType
impl DataTypeTraits for ComplexFloat8E3M4DataType
impl DataTypeTraits for ComplexFloat8E4M3B11FNUZDataType
impl DataTypeTraits for ComplexFloat8E4M3DataType
float8 only.impl DataTypeTraits for ComplexFloat8E4M3FNUZDataType
impl DataTypeTraits for ComplexFloat8E5M2DataType
float8 only.impl DataTypeTraits for ComplexFloat8E5M2FNUZDataType
impl DataTypeTraits for ComplexFloat8E8M0FNUDataType
impl DataTypeTraits for ComplexFloat16DataType
impl DataTypeTraits for ComplexFloat32DataType
impl DataTypeTraits for ComplexFloat64DataType
impl DataTypeTraits for Float4E2M1FNDataType
impl DataTypeTraits for Float6E2M3FNDataType
impl DataTypeTraits for Float6E3M2FNDataType
impl DataTypeTraits for Float8E3M4DataType
impl DataTypeTraits for Float8E4M3B11FNUZDataType
impl DataTypeTraits for Float8E4M3DataType
float8 only.impl DataTypeTraits for Float8E4M3FNUZDataType
impl DataTypeTraits for Float8E5M2DataType
float8 only.