pub struct LimitWriter<W> { /* private fields */ }Expand description
Writer wrapper that accepts at most a fixed number of bytes.
Once the remaining limit reaches zero, writes return Ok(0) without
touching the inner writer. Callers using Write::write_all will therefore
receive the standard write-zero error when trying to write beyond the limit.
§Examples
use std::io::Write;
use qubit_io::LimitWriter;
let mut writer = LimitWriter::new(Vec::new(), 3);
assert_eq!(3, writer.write(b"abcdef")?);
assert_eq!(0, writer.remaining());
assert_eq!(0, writer.write(b"x")?);
assert_eq!(b"abc", writer.get_ref().as_slice());Implementations§
Source§impl<W> LimitWriter<W>
impl<W> LimitWriter<W>
Sourcepub fn remaining(&self) -> u64
pub fn remaining(&self) -> u64
Returns the number of bytes still accepted by this wrapper.
§Returns
Remaining writable byte count before the wrapper reports zero writes.
Sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Trait Implementations§
Source§impl<W> Write for LimitWriter<W>where
W: Write,
impl<W> Write for LimitWriter<W>where
W: Write,
Source§fn write(&mut self, buffer: &[u8]) -> Result<usize>
fn write(&mut self, buffer: &[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<W> Freeze for LimitWriter<W>where
W: Freeze,
impl<W> RefUnwindSafe for LimitWriter<W>where
W: RefUnwindSafe,
impl<W> Send for LimitWriter<W>where
W: Send,
impl<W> Sync for LimitWriter<W>where
W: Sync,
impl<W> Unpin for LimitWriter<W>where
W: Unpin,
impl<W> UnsafeUnpin for LimitWriter<W>where
W: UnsafeUnpin,
impl<W> UnwindSafe for LimitWriter<W>where
W: UnwindSafe,
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