Skip to main content

DataTypeTraits

Trait DataTypeTraits 

Source
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§

Source

fn configuration(&self, version: ZarrVersion) -> Configuration

The configuration of the data type.

Source

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).

Source

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.

Source

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.

Source

fn as_any(&self) -> &(dyn Any + 'static)

Returns self as Any for downcasting.

This enables accessing concrete type-specific methods (like OptionalDataType::data_type()).

Provided Methods§

Source

fn configuration_v3(&self) -> Configuration

The Zarr V3 configuration of the data type.

Source

fn configuration_v2(&self) -> Configuration

The Zarr V2 configuration of the data type.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl DataTypeTraits for BFloat16DataType

Source§

impl DataTypeTraits for BoolDataType

Source§

impl DataTypeTraits for BytesDataType

Source§

impl DataTypeTraits for Complex64DataType

Source§

impl DataTypeTraits for Complex128DataType

Source§

impl DataTypeTraits for ComplexBFloat16DataType

Source§

impl DataTypeTraits for ComplexFloat4E2M1FNDataType

Source§

impl DataTypeTraits for ComplexFloat6E2M3FNDataType

Source§

impl DataTypeTraits for ComplexFloat6E3M2FNDataType

Source§

impl DataTypeTraits for ComplexFloat8E3M4DataType

Source§

impl DataTypeTraits for ComplexFloat8E4M3B11FNUZDataType

Source§

impl DataTypeTraits for ComplexFloat8E4M3DataType

Available on crate feature float8 only.
Source§

impl DataTypeTraits for ComplexFloat8E4M3FNUZDataType

Source§

impl DataTypeTraits for ComplexFloat8E5M2DataType

Available on crate feature float8 only.
Source§

impl DataTypeTraits for ComplexFloat8E5M2FNUZDataType

Source§

impl DataTypeTraits for ComplexFloat8E8M0FNUDataType

Source§

impl DataTypeTraits for ComplexFloat16DataType

Source§

impl DataTypeTraits for ComplexFloat32DataType

Source§

impl DataTypeTraits for ComplexFloat64DataType

Source§

impl DataTypeTraits for Float4E2M1FNDataType

Source§

impl DataTypeTraits for Float6E2M3FNDataType

Source§

impl DataTypeTraits for Float6E3M2FNDataType

Source§

impl DataTypeTraits for Float8E3M4DataType

Source§

impl DataTypeTraits for Float8E4M3B11FNUZDataType

Source§

impl DataTypeTraits for Float8E4M3DataType

Available on crate feature float8 only.
Source§

impl DataTypeTraits for Float8E4M3FNUZDataType

Source§

impl DataTypeTraits for Float8E5M2DataType

Available on crate feature float8 only.
Source§

impl DataTypeTraits for Float8E5M2FNUZDataType

Source§

impl DataTypeTraits for Float8E8M0FNUDataType

Source§

impl DataTypeTraits for Float16DataType

Source§

impl DataTypeTraits for Float32DataType

Source§

impl DataTypeTraits for Float64DataType

Source§

impl DataTypeTraits for Int2DataType

Source§

impl DataTypeTraits for Int4DataType

Source§

impl DataTypeTraits for Int8DataType

Source§

impl DataTypeTraits for Int16DataType

Source§

impl DataTypeTraits for Int32DataType

Source§

impl DataTypeTraits for Int64DataType

Source§

impl DataTypeTraits for NumpyDateTime64DataType

Source§

impl DataTypeTraits for NumpyTimeDelta64DataType

Source§

impl DataTypeTraits for OptionalDataType

Source§

impl DataTypeTraits for RawBitsDataType

Source§

impl DataTypeTraits for StringDataType

Source§

impl DataTypeTraits for UInt2DataType

Source§

impl DataTypeTraits for UInt4DataType

Source§

impl DataTypeTraits for UInt8DataType

Source§

impl DataTypeTraits for UInt16DataType

Source§

impl DataTypeTraits for UInt32DataType

Source§

impl DataTypeTraits for UInt64DataType