Struct npyz::NpyWriter[][src]

pub struct NpyWriter<Row: Serialize + ?Sized, W: Write> { /* fields omitted */ }
Expand description

Interface for writing an NPY file to a data stream.

To construct an instance of this, you must go through the WriterBuilder trait:

use npyz::WriterBuilder;

fn main() -> std::io::Result<()> {
    // Any io::Write is supported.  For this example we'll
    // use Vec<u8> to serialize in-memory.
    let mut out_buf = vec![];
    let mut writer = {
        npyz::WriteOptions::new()
            .default_dtype()
            .shape(&[2, 3])
            .writer(&mut out_buf)
            .begin_nd()?
    };

    writer.push(&100)?;
    writer.push(&101)?;
    writer.push(&102)?;
    // can write elements from iterators too
    writer.extend(vec![200, 201, 202])?;
    writer.finish()?;

    eprintln!("{:02x?}", out_buf);
    Ok(())
}

Implementations

👎 Deprecated since 0.5.0:

Doesn’t carry its weight. Use to_file_1d instead, or replicate the original behavior with Builder::new().default_dtype().begin_1d(std::io::BufWriter::new(std::fs::File::create(path)?))

Create a file, using the default format for the given type.

👎 Deprecated since 0.5.0:

use .finish() instead

Finish writing the file and close it. Alias for NpyWriter::finish.

If omitted, the file will be closed on drop automatically, ignoring any errors encountered during the process.

Append a single row to the file

Write an iterator to the file

Finish writing the file.

If no shape was provided, this will update the header to reflect the number of elements written. If a shape was provided and the number of inserted elements is incorrect, an error is returned.

This is automatically called on drop, but in that case, errors are ignored.

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.