Trait npyz::Serialize

source ·
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§

source

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§

source

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§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Serialize for bool

§

type TypeWriter = PrimitiveWriter<bool>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for f32

§

type TypeWriter = PrimitiveWriter<f32>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for f64

§

type TypeWriter = PrimitiveWriter<f64>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for i8

§

type TypeWriter = PrimitiveWriter<i8>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for i16

§

type TypeWriter = PrimitiveWriter<i16>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for i32

§

type TypeWriter = PrimitiveWriter<i32>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for i64

§

type TypeWriter = PrimitiveWriter<i64>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for str

§

type TypeWriter = StrWriter

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for u8

§

type TypeWriter = PrimitiveWriter<u8>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for u16

§

type TypeWriter = PrimitiveWriter<u16>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for u32

§

type TypeWriter = PrimitiveWriter<u32>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for u64

§

type TypeWriter = PrimitiveWriter<u64>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for String

§

type TypeWriter = TypeWriteViaDeref<String>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for Vec<char>

§

type TypeWriter = TypeWriteViaDeref<Vec<char>>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for Vec<u8>

§

type TypeWriter = TypeWriteViaDeref<Vec<u8>>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for Vec<u32>

§

type TypeWriter = TypeWriteViaDeref<Vec<u32>>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for f16

§

type TypeWriter = PrimitiveWriter<f16>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for Complex<f32>

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

§

type TypeWriter = ComplexWriter<f32>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for Complex<f64>

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

§

type TypeWriter = ComplexWriter<f64>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for [char]

§

type TypeWriter = Utf32Writer

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for [u8]

§

type TypeWriter = BytesWriter

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl Serialize for [u32]

§

type TypeWriter = Utf32WithSurrogatesWriter

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl<'a, T> Serialize for Cow<'a, T>
where T: Serialize + ToOwned + ?Sized,

§

type TypeWriter = TypeWriteViaDeref<Cow<'a, T>>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl<'a, T> Serialize for &'a T
where T: Serialize + ?Sized,

§

type TypeWriter = TypeWriteViaDeref<&'a T>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl<'a, T> Serialize for &'a mut T
where T: Serialize + ?Sized,

§

type TypeWriter = TypeWriteViaDeref<&'a mut T>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl<T> Serialize for Box<T>
where T: Serialize + ?Sized,

§

type TypeWriter = TypeWriteViaDeref<Box<T>>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl<T> Serialize for Rc<T>
where T: Serialize + ?Sized,

§

type TypeWriter = TypeWriteViaDeref<Rc<T>>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl<T> Serialize for Arc<T>
where T: Serialize + ?Sized,

§

type TypeWriter = TypeWriteViaDeref<Arc<T>>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

impl<T: Serialize, const N: usize> Serialize for [T; N]

§

type TypeWriter = ArrayWriter<<T as Serialize>::TypeWriter, N>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

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

This impl is only available with the arrayvec feature.

§

type TypeWriter = TypeWriteViaDeref<ArrayString<N>>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

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

This impl is only available with the arrayvec feature.

§

type TypeWriter = TypeWriteViaDeref<ArrayVec<char, N>>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

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

This impl is only available with the arrayvec feature.

§

type TypeWriter = ArrayVecBytesWriter<N>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

source§

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

This impl is only available with the arrayvec feature.

§

type TypeWriter = TypeWriteViaDeref<ArrayVec<u32, N>>

source§

fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>

Implementors§

source§

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

§

type TypeWriter = FixedSizeBytesWriter<N>