Trait npyz::Deserialize [−][src]
pub trait Deserialize: Sized { type TypeReader: TypeRead<Value = Self>; fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>; }
Expand description
Trait that permits reading a type from an .npy
file.
Examples of types that implement this:
- Primitive integers, floats,
Complex
(with the"complex"
feature) - Owned byte containers (
Vec<u8>
)
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.
Associated Types
type TypeReader: TypeRead<Value = Self>
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
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
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
.
Implementations on Foreign Types
type TypeReader = PrimitiveReader<i8>
type TypeReader = PrimitiveReader<i16>
type TypeReader = PrimitiveReader<i32>
type TypeReader = PrimitiveReader<i64>
type TypeReader = PrimitiveReader<u8>
type TypeReader = PrimitiveReader<u16>
type TypeReader = PrimitiveReader<u32>
type TypeReader = PrimitiveReader<u64>
type TypeReader = PrimitiveReader<f32>
type TypeReader = PrimitiveReader<f64>
type TypeReader = BytesReader
type TypeReader = ArrayReader<<T as Deserialize>::TypeReader, N>