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§
sourcetype 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§
sourcefn 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
.
Object Safety§
Implementations on Foreign Types§
source§impl Deserialize for bool
impl Deserialize for bool
type TypeReader = PrimitiveReader<bool>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for f32
impl Deserialize for f32
type TypeReader = PrimitiveReader<f32>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for f64
impl Deserialize for f64
type TypeReader = PrimitiveReader<f64>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for i8
impl Deserialize for i8
type TypeReader = PrimitiveReader<i8>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for i16
impl Deserialize for i16
type TypeReader = PrimitiveReader<i16>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for i32
impl Deserialize for i32
type TypeReader = PrimitiveReader<i32>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for i64
impl Deserialize for i64
type TypeReader = PrimitiveReader<i64>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for u8
impl Deserialize for u8
type TypeReader = PrimitiveReader<u8>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for u16
impl Deserialize for u16
type TypeReader = PrimitiveReader<u16>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for u32
impl Deserialize for u32
type TypeReader = PrimitiveReader<u32>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for u64
impl Deserialize for u64
type TypeReader = PrimitiveReader<u64>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for String
impl Deserialize for String
type TypeReader = StringReader
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for Vec<char>
impl Deserialize for Vec<char>
type TypeReader = Utf32Reader
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for Vec<u8>
impl Deserialize for Vec<u8>
type TypeReader = BytesReader
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for Vec<u32>
impl Deserialize for Vec<u32>
type TypeReader = Utf32WithSurrogatesReader
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for f16
impl Deserialize for f16
type TypeReader = PrimitiveReader<f16>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for Complex<f32>
impl Deserialize for Complex<f32>
This impl is only available with the "complex"
feature.
type TypeReader = ComplexReader<f32>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl Deserialize for Complex<f64>
impl Deserialize for Complex<f64>
This impl is only available with the "complex"
feature.
type TypeReader = ComplexReader<f64>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl<T: Deserialize + Default + Copy, const N: usize> Deserialize for [T; N]
impl<T: Deserialize + Default + Copy, const N: usize> Deserialize for [T; N]
type TypeReader = ArrayReader<<T as Deserialize>::TypeReader, N>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl<const N: usize> Deserialize for ArrayString<N>
impl<const N: usize> Deserialize for ArrayString<N>
This impl is only available with the "arrayvec"
feature.
type TypeReader = Utf8ArrayStringReader<N>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl<const N: usize> Deserialize for ArrayVec<char, N>
impl<const N: usize> Deserialize for ArrayVec<char, N>
This impl is only available with the "arrayvec"
feature.
type TypeReader = Utf32ArrayVecReader<N>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl<const N: usize> Deserialize for ArrayVec<u8, N>
impl<const N: usize> Deserialize for ArrayVec<u8, N>
This impl is only available with the arrayvec
feature.
type TypeReader = ArrayVecBytesReader<N>
fn reader(dtype: &DType) -> Result<Self::TypeReader, DTypeError>
source§impl<const N: usize> Deserialize for ArrayVec<u32, N>
impl<const N: usize> Deserialize for ArrayVec<u32, N>
This impl is only available with the "arrayvec"
feature.