#macro-derive #npy #numpy #serializable #serialization #format #file-format

macro npy-derive

Macros 1.1 implementation of #[derive(Serializable)] for crate npy

6 releases (3 breaking)

Uses old Rust 2015

0.4.0 Mar 5, 2018
0.3.1 Sep 19, 2017
0.3.0 Aug 20, 2017
0.2.1 Mar 13, 2017
0.1.0 Mar 7, 2017

#8 in #npy

Download history 38/week @ 2024-07-22 47/week @ 2024-07-29 30/week @ 2024-08-05 19/week @ 2024-08-12 32/week @ 2024-08-26 13/week @ 2024-09-02 27/week @ 2024-09-09 26/week @ 2024-09-16 49/week @ 2024-09-23 11/week @ 2024-09-30 2/week @ 2024-10-07 36/week @ 2024-10-14 24/week @ 2024-10-21 43/week @ 2024-10-28 17/week @ 2024-11-04

120 downloads per month
Used in npy

MIT license

5KB
72 lines

npy-rs

crates.io version Documentation Build Status

Numpy format (*.npy) serialization and deserialization.

NPY is a simple binary data format. It stores the type, shape and endianness information in a header, which is followed by a flat binary data field. This crate offers a simple, mostly type-safe way to read and write *.npy files. Files are handled using iterators, so they don't need to fit in memory.

Usage

To use npy-rs, two dependencies must be specified in Cargo.toml:

npy = "0.4"
npy-derive = "0.4"

A typical way to import everything needed is:

#[macro_use]
extern crate npy_derive;
extern crate npy;

The npy-derive dependency is only needed for structured array serialization.

Data can now be imported from a *.npy file:

use npy::NpyData;

std::fs::File::open("data.npy").unwrap().read_to_end(&mut buf).unwrap();
let data: Vec<f64> = NpyData::from_bytes(&buf).unwrap().to_vec();

and exported to a *.npy file:

npy::to_file("data.npy", data).unwrap();

See the documentation for more information.

Several usage examples are available in the examples directory; the simple example shows how to load a file, roundtrip shows both reading and writing. Large files can be memory-mapped as illustrated in the large example.

Documentation


lib.rs:

Derive trait Serializable for a structure.

Using this crate, it is enough to #[derive(Serializable)] on a struct to be able to serialize and deserialize it. All the fields must implement Serializable.

Dependencies

~2MB
~48K SLoC