pub struct BoundedWriter<W> { /* private fields */ }Expand description
A byte allowance and successful-write counter around a caller-owned sink.
Oversized offered buffers are rejected in full before invoking the sink. Short writes count only accepted bytes. Read limits, encoding, hashing, synchronization, atomic publication and cleanup stay with their owners. A sink’s internal buffering/allocation and partial effects on error are not controlled here. Do not publish partial output after a failed producer.
Use io::sink to count serialized bytes without retaining them, or a
hashing dependency’s existing Write implementation to bound its input.
Implementations§
Source§impl<W> BoundedWriter<W>
impl<W> BoundedWriter<W>
Sourcepub const fn new(inner: W, limit: u64) -> Self
pub const fn new(inner: W, limit: u64) -> Self
Select the sink and the inclusive total accepted-byte allowance.
Sourcepub const fn bytes_written(&self) -> u64
pub const fn bytes_written(&self) -> u64
Bytes reported as accepted by successful underlying writes.
This is neither a durability receipt nor an assertion of serialization
success. Underlying errors may have effects not reported by Write.
Sourcepub const fn limit_exceeded(&self) -> bool
pub const fn limit_exceeded(&self) -> bool
Whether any offered buffer has been rejected by this byte allowance.
Retained even when an encoder hides the underlying typed IO error. A limit rejection leaves the sink and counter unchanged; later writes that fit are permitted, without clearing this observation.
Sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Recover the original sink, including any partial output after failure.
Does not flush, synchronize, retry, publish or discard output. Callers must explicitly flush through this wrapper when their sink requires it.
Trait Implementations§
Source§impl<W: Write> Write for BoundedWriter<W>
impl<W: Write> Write for BoundedWriter<W>
Source§fn write(&mut self, buffer: &[u8]) -> Result<usize>
fn write(&mut self, buffer: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
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)