Trait npyz::Deserialize

source ·
pub trait Deserialize: Sized {
    type TypeReader: TypeRead<Value = Self>;

    // Required method
    fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>;
}
Expand description

Trait that permits reading a type from an .npy file.

Complete documentation of all types that implement this trait is available on the type_matchup_docs module.

Examples of types that implement this:

  • Primitive integers, floats, Complex (with the "complex" feature)
  • Owned containers (Vec<u8>, String)

This trait is derivable when enabling the "derive" feature. This makes it easier to work with structured arrays.

For an example of how to implement this manually, see Vector5 in the roundtrip test.

Required Associated Types§

source

type TypeReader: TypeRead<Value = Self>

Think of this as like a for<R: io::Read> Fn(R) -> io::Result<Self>.

There is no closure-like sugar for these; you must manually define a type that implements TypeRead.

Required Methods§

source

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

Get a function that deserializes a single data field at a time.

The purpose of the dtype arugment is to allow e.g. specifying a length for string types, or the endianness for integers.

Errors

Returns Err if the DType is not compatible with Self.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Deserialize for bool

§

type TypeReader = PrimitiveReader<bool>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for f32

§

type TypeReader = PrimitiveReader<f32>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for f64

§

type TypeReader = PrimitiveReader<f64>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for i8

§

type TypeReader = PrimitiveReader<i8>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for i16

§

type TypeReader = PrimitiveReader<i16>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for i32

§

type TypeReader = PrimitiveReader<i32>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for i64

§

type TypeReader = PrimitiveReader<i64>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for u8

§

type TypeReader = PrimitiveReader<u8>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for u16

§

type TypeReader = PrimitiveReader<u16>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for u32

§

type TypeReader = PrimitiveReader<u32>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for u64

§

type TypeReader = PrimitiveReader<u64>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for String

§

type TypeReader = StringReader

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for Vec<char>

§

type TypeReader = Utf32Reader

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for Vec<u8>

§

type TypeReader = BytesReader

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for Vec<u32>

§

type TypeReader = Utf32WithSurrogatesReader

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for f16

§

type TypeReader = PrimitiveReader<f16>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for Complex<f32>

This impl is only available with the "complex" feature.

§

type TypeReader = ComplexReader<f32>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl Deserialize for Complex<f64>

This impl is only available with the "complex" feature.

§

type TypeReader = ComplexReader<f64>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl<T: Deserialize + Default + Copy, const N: usize> Deserialize for [T; N]

§

type TypeReader = ArrayReader<<T as Deserialize>::TypeReader, N>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl<const N: usize> Deserialize for ArrayString<N>

This impl is only available with the "arrayvec" feature.

§

type TypeReader = Utf8ArrayStringReader<N>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl<const N: usize> Deserialize for ArrayVec<char, N>

This impl is only available with the "arrayvec" feature.

§

type TypeReader = Utf32ArrayVecReader<N>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl<const N: usize> Deserialize for ArrayVec<u8, N>

This impl is only available with the arrayvec feature.

§

type TypeReader = ArrayVecBytesReader<N>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

source§

impl<const N: usize> Deserialize for ArrayVec<u32, N>

This impl is only available with the "arrayvec" feature.

§

type TypeReader = Utf32WithSurrogatesArrayVecReader<N>

source§

fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>

Implementors§

source§

impl<const N: usize> Deserialize for FixedSizeBytes<N>

§

type TypeReader = FixedSizeBytesReader<N>