potocpav / npy-rs

NumPy file format (de-)serialization in Rust
30 stars 7 forks source link

Allow OutFile to write to any Write + Seek #16

Open ExpHP opened 5 years ago

ExpHP commented 5 years ago

This is a small thing I need for some of the unit tests I'm adding to #15.

In order to be backwards compatible, OutFile becomes a type alias for a new, more general type:

pub struct NpyWriter<T: npy::Serializable, W: io::Write + io::Seek> { ... }

impl<T: npy::Serializable, W: io::Write + io::Seek> NpyWriter {
    pub fn begin(W) -> io::Result<Self>;
    pub fn push(&mut self, &T) -> io::Result<()>;
    pub fn finish(self) -> io::Result<()>;
}

pub type OutFile<T> = NpyWriter<T, BufWriter<File>>;

close was renamed to finish to avoid suggesting that it closes any resources. OutFile::close still exists as an alias for finish.