DataTypeExtension

Trait DataTypeExtension 

Source
pub trait DataTypeExtension:
    Debug
    + MaybeSend
    + MaybeSync {
    // Required methods
    fn identifier(&self) -> &'static str;
    fn configuration(&self) -> Configuration;
    fn size(&self) -> DataTypeSize;
    fn fill_value(
        &self,
        fill_value_metadata: &FillValueMetadataV3,
    ) -> Result<FillValue, DataTypeFillValueMetadataError>;
    fn metadata_fill_value(
        &self,
        fill_value: &FillValue,
    ) -> Result<FillValueMetadataV3, DataTypeFillValueError>;
    fn as_any(&self) -> &dyn Any;

    // Provided methods
    fn default_name(
        &self,
        zarr_version: ZarrVersions,
    ) -> Option<Cow<'static, str>> { ... }
    fn eq(&self, other: &dyn DataTypeExtension) -> bool { ... }
}
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 identifier(&self) -> &'static str

The identifier of the data type.

Source

fn configuration(&self) -> 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, ) -> 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

Returns self as Any for downcasting.

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

Provided Methods§

Source

fn default_name(&self, zarr_version: ZarrVersions) -> Option<Cow<'static, str>>

The name to use when creating metadata for this data type.

This is used when creating metadata. Most data types return their identifier, but some (like RawBitsDataType) return a version-specific name like r{bits}.

Source

fn eq(&self, other: &dyn DataTypeExtension) -> bool

Compare this data type with another for equality.

The default implementation compares identifier and configuration. Custom data types may override this for more efficient comparison.

Implementors§