Struct npyz::NpyWriter [−][src]
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)?))
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
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.
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
Auto Trait Implementations
impl<Row, W> !RefUnwindSafe for NpyWriter<Row, W>
impl<Row: ?Sized, W> Unpin for NpyWriter<Row, W> where
W: Unpin,
<Row as Serialize>::TypeWriter: Unpin,
impl<Row, W> !UnwindSafe for NpyWriter<Row, W>