Trait npyz::Serialize[][src]

pub trait Serialize {
    type TypeWriter: TypeWrite<Value = Self>;
    fn writer(dtype: &DType) -> Result<Self::TypeWriter, DTypeError>;
}
Expand description

Trait that permits writing a type to an .npy file.

Examples of types that implement this:

  • Primitive integers, floats, Complex (with the "complex" feature)
  • Byte slices ([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

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

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.

Implementations on Foreign Types

This impl is only available with the complex feature.

This impl is only available with the complex feature.

Implementors