pub trait Serialize {
type TypeWriter: TypeWrite<Value = Self>;
// Required method
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>;
}
Expand description
Trait that permits writing a type to 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) - Slice types (
[u8]
,str
)
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 TypeWriter: TypeWrite<Value = Self>
type TypeWriter: TypeWrite<Value = Self>
Think of this as some sort of for<W: io::Write> Fn(W, &Self) -> io::Result<()>
.
There is no closure-like sugar for these; you must manually define a type that
implements TypeWrite
.
Required Methods§
sourcefn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
Get a function that serializes 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. The derivable AutoSerialize
trait is able to supply
many types with a reasonable default.
Errors
Returns Err
if the DType
is not compatible with Self
.
Object Safety§
Implementations on Foreign Types§
source§impl Serialize for bool
impl Serialize for bool
type TypeWriter = PrimitiveWriter<bool>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for f32
impl Serialize for f32
type TypeWriter = PrimitiveWriter<f32>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for f64
impl Serialize for f64
type TypeWriter = PrimitiveWriter<f64>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for i8
impl Serialize for i8
type TypeWriter = PrimitiveWriter<i8>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for i16
impl Serialize for i16
type TypeWriter = PrimitiveWriter<i16>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for i32
impl Serialize for i32
type TypeWriter = PrimitiveWriter<i32>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for i64
impl Serialize for i64
type TypeWriter = PrimitiveWriter<i64>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for str
impl Serialize for str
type TypeWriter = StrWriter
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for u8
impl Serialize for u8
type TypeWriter = PrimitiveWriter<u8>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for u16
impl Serialize for u16
type TypeWriter = PrimitiveWriter<u16>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for u32
impl Serialize for u32
type TypeWriter = PrimitiveWriter<u32>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for u64
impl Serialize for u64
type TypeWriter = PrimitiveWriter<u64>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for String
impl Serialize for String
type TypeWriter = TypeWriteViaDeref<String>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for Vec<char>
impl Serialize for Vec<char>
type TypeWriter = TypeWriteViaDeref<Vec<char>>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for Vec<u8>
impl Serialize for Vec<u8>
type TypeWriter = TypeWriteViaDeref<Vec<u8>>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for Vec<u32>
impl Serialize for Vec<u32>
type TypeWriter = TypeWriteViaDeref<Vec<u32>>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for f16
impl Serialize for f16
type TypeWriter = PrimitiveWriter<f16>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for Complex<f32>
impl Serialize for Complex<f32>
This impl is only available with the "complex"
feature.
type TypeWriter = ComplexWriter<f32>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for Complex<f64>
impl Serialize for Complex<f64>
This impl is only available with the "complex"
feature.
type TypeWriter = ComplexWriter<f64>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for [char]
impl Serialize for [char]
type TypeWriter = Utf32Writer
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for [u8]
impl Serialize for [u8]
type TypeWriter = BytesWriter
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl Serialize for [u32]
impl Serialize for [u32]
type TypeWriter = Utf32WithSurrogatesWriter
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl<'a, T> Serialize for Cow<'a, T>
impl<'a, T> Serialize for Cow<'a, T>
type TypeWriter = TypeWriteViaDeref<Cow<'a, T>>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl<'a, T> Serialize for &'a T
impl<'a, T> Serialize for &'a T
type TypeWriter = TypeWriteViaDeref<&'a T>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl<'a, T> Serialize for &'a mut T
impl<'a, T> Serialize for &'a mut T
type TypeWriter = TypeWriteViaDeref<&'a mut T>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl<T> Serialize for Box<T>
impl<T> Serialize for Box<T>
type TypeWriter = TypeWriteViaDeref<Box<T>>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl<T> Serialize for Rc<T>
impl<T> Serialize for Rc<T>
type TypeWriter = TypeWriteViaDeref<Rc<T>>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl<T> Serialize for Arc<T>
impl<T> Serialize for Arc<T>
type TypeWriter = TypeWriteViaDeref<Arc<T>>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl<T: Serialize, const N: usize> Serialize for [T; N]
impl<T: Serialize, const N: usize> Serialize for [T; N]
type TypeWriter = ArrayWriter<<T as Serialize>::TypeWriter, N>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl<const N: usize> Serialize for ArrayString<N>
impl<const N: usize> Serialize for ArrayString<N>
This impl is only available with the arrayvec
feature.
type TypeWriter = TypeWriteViaDeref<ArrayString<N>>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl<const N: usize> Serialize for ArrayVec<char, N>
impl<const N: usize> Serialize for ArrayVec<char, N>
This impl is only available with the arrayvec
feature.
type TypeWriter = TypeWriteViaDeref<ArrayVec<char, N>>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl<const N: usize> Serialize for ArrayVec<u8, N>
impl<const N: usize> Serialize for ArrayVec<u8, N>
This impl is only available with the arrayvec
feature.
type TypeWriter = ArrayVecBytesWriter<N>
fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>
source§impl<const N: usize> Serialize for ArrayVec<u32, N>
impl<const N: usize> Serialize for ArrayVec<u32, N>
This impl is only available with the arrayvec
feature.