pub struct SpareWriter<'a> { /* private fields */ }Expand description
Appends bytes to the spare capacity of a BytesMut.
Created by BytesMut::spare_writer. Bytes are written into the spare
capacity, which is not initialized first, and the writer reserves more
capacity when it is full, at least doubling the buffer capacity. The
buffer length is updated when the writer is dropped. If the writer is
leaked, the buffer may not include all of the written bytes.
Implementations§
Source§impl SpareWriter<'_>
impl SpareWriter<'_>
Sourcepub fn extend_from_slice(&mut self, src: &[u8])
pub fn extend_from_slice(&mut self, src: &[u8])
Appends a byte slice.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more bytes after the
written bytes.
§Panics
Panics if the new capacity exceeds u32::MAX minus the buffer
header size, just under 4 GiB.
Sourcepub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<u8>]
pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<u8>]
Returns the spare capacity after the written bytes.
Bytes written into it are added to the writer with
advance.
§Examples
use ntex_bytes::BytesMut;
let mut buf = BytesMut::new();
let mut w = buf.spare_writer(0);
w.reserve(2);
let spare = w.spare_capacity_mut();
spare[0].write(b'o');
spare[1].write(b'k');
// SAFETY: The first two bytes of the spare capacity are initialized
unsafe { w.advance(2) };
drop(w);
assert_eq!(&buf[..], b"ok");Sourcepub unsafe fn advance(&mut self, cnt: usize)
pub unsafe fn advance(&mut self, cnt: usize)
Adds cnt bytes of the spare capacity to the written bytes.
§Safety
The first cnt bytes of spare_capacity_mut
must be initialized.
Trait Implementations§
Source§impl Debug for SpareWriter<'_>
impl Debug for SpareWriter<'_>
Source§impl Drop for SpareWriter<'_>
impl Drop for SpareWriter<'_>
impl Send for SpareWriter<'_>
impl Sync for SpareWriter<'_>
Source§impl Write for SpareWriter<'_>
impl Write for SpareWriter<'_>
Source§fn write(&mut self, src: &[u8]) -> Result<usize, Error>
fn write(&mut self, src: &[u8]) -> Result<usize, Error>
Source§fn flush(&mut self) -> Result<(), Error>
fn flush(&mut self) -> Result<(), Error>
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)