pub struct DatasetWriter { /* private fields */ }Expand description
Wrapper for easier Dataset generation
This type can be used to write data to a file and then automatically generate an id and calculate a hash for the file. The hash algorithm used is SHA-512 (see also Dataset::from_file).
This type implements Write and Seek and therefor can be used together with things like serde_json::to_writer or similar functions.
§Example
let mut writer = DatasetWriter::new("output/data")?;
serde_json::to_writer(&mut writer, &[0, 1, 2])?;
let dataset = writer.finalize(())?;
dbsession.add_dataset(&dataset)?;Implementations§
Source§impl DatasetWriter
impl DatasetWriter
Sourcepub fn new<P: AsRef<Path>>(folder: P) -> Result<Self, Error>
pub fn new<P: AsRef<Path>>(folder: P) -> Result<Self, Error>
Create new writer
This generates an id uses this as a filename to create a file in folder.
If the path did not exist before, parent folders are created.
Trait Implementations§
Source§impl Seek for DatasetWriter
Available on crate feature sha only.
impl Seek for DatasetWriter
Available on crate feature
sha only.Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
Seek to an offset, in bytes, in a stream. Read more
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Rewind to the beginning of a stream. Read more
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
🔬This is a nightly-only experimental API. (
seek_stream_len)Returns the length of this stream (in bytes). Read more
Source§impl Write for DatasetWriter
Available on crate feature sha only.
impl Write for DatasetWriter
Available on crate feature
sha only.Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Writes a buffer into this writer, returning how many bytes were written. Read more
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flushes this output stream, ensuring that all intermediately buffered
contents reach their destination. Read more
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this writer. Read more
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
write_all_vectored)Attempts to write multiple buffers into this writer. Read more
Auto Trait Implementations§
impl Freeze for DatasetWriter
impl RefUnwindSafe for DatasetWriter
impl Send for DatasetWriter
impl Sync for DatasetWriter
impl Unpin for DatasetWriter
impl UnwindSafe for DatasetWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more