pub struct DeferredWriter<'a> { /* private fields */ }
Expand description
A buffered writer with deferred error checking.
This can be used like std::io::BufWriter
, but like DeferredReader
this performs deferred error checking. This means that any call to write
, will
always succeed. IO errors that occur during writing will be reported during the next call to
flush
or check_io_error
. Any data written after an
IO error occured, before it is eventually reported, will be discarded.
Deferring error checks like this can result in a significant speed up for some usage patterns.
Implementations§
Source§impl<'a> DeferredWriter<'a>
impl<'a> DeferredWriter<'a>
Sourcepub fn from_write(write: impl Write + 'a) -> Self
pub fn from_write(write: impl Write + 'a) -> Self
Creates a DeferredWriter
writing data to a Write
instance.
Sourcepub fn from_boxed_dyn_write(write: Box<dyn Write + 'a>) -> Self
pub fn from_boxed_dyn_write(write: Box<dyn Write + 'a>) -> Self
Creates a DeferredWriter
writing data to a boxed Write
instance.
Sourcepub fn flush_defer_err(&mut self)
pub fn flush_defer_err(&mut self)
Flush the buffered data to the underlying Write
instance, deferring IO errors.
Sourcepub fn write_all_defer_err(&mut self, buf: &[u8])
pub fn write_all_defer_err(&mut self, buf: &[u8])
Sourcepub fn buf_write_ptr(&mut self, len: usize) -> *mut u8
pub fn buf_write_ptr(&mut self, len: usize) -> *mut u8
Returns a pointer to the current write pointer within the internal buffer if sufficient space is available.
If only fewer than len
bytes are available, this returns a null pointer.
Can be used in conjunction with advance_unchecked
to construct
output data directly within the output buffer, potentially avoiding a redundant copy.
Sourcepub unsafe fn advance_unchecked(&mut self, len: usize)
pub unsafe fn advance_unchecked(&mut self, len: usize)
Advances the write pointer within the internal buffer.
§Safety
This assumes that a) there is sufficient space left in the buffer and b) that the bytes the
pointer is advanced over were initialized prior to calling this (via
buf_write_ptr
).
If either assumption does not hold calling this results in undefined behavior.
Sourcepub fn check_io_error(&mut self) -> Result<()>
pub fn check_io_error(&mut self) -> Result<()>
Returns an encountered IO errors as Err(io_err)
.
This resets the stored IO error and returns Ok(())
if no IO error is stored.
Trait Implementations§
Source§impl<'a> Drop for DeferredWriter<'a>
impl<'a> Drop for DeferredWriter<'a>
Source§impl<'a> Write for DeferredWriter<'a>
impl<'a> Write for DeferredWriter<'a>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)