pub struct ReadBuf { /* private fields */ }Expand description
A wrapper around a byte buffer that is incrementally filled and initialized.
This type is a sort of “double cursor”. It tracks three regions in the buffer: a region at the beginning of the buffer that has been logically filled with data, a region that has been initialized at some point but not yet logically filled, and a region at the end that may be uninitialized. The filled region is guaranteed to be a subset of the initialized region.
In summary, the contents of the buffer can be visualized as:
[ capacity ]
[ filled | unfilled ]
[ initialized | uninitialized ]It is undefined behavior to de-initialize any bytes from the uninitialized region, since it is merely unknown whether this region is uninitialized or not, and if part of it turns out to be initialized, it must stay initialized.
Implementations§
Source§impl ReadBuf
impl ReadBuf
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new ReadBuf with the specified capacity.
The returned ReadBuf will be able to hold at least capacity bytes
without reallocating.
Sourcepub fn chunk_mut(&mut self) -> &mut [u8] ⓘ
pub fn chunk_mut(&mut self) -> &mut [u8] ⓘ
Returns a mutable slice starting at the current BufMut position and of
length between 0 and ReadBuf::remaining_mut(). Note that this can be shorter than the
whole remainder of the buffer (this allows non-continuous implementation).
Sourcepub fn remaining_mut(&self) -> usize
pub fn remaining_mut(&self) -> usize
Returns the number of bytes that can be written from the current position until the end of the buffer is reached.
This value is greater than or equal to the length of the slice returned
by chunk_mut().
Sourcepub fn advance_mut(&mut self, advance: usize)
pub fn advance_mut(&mut self, advance: usize)
Advance the internal cursor of the BufMut
The next call to chunk_mut will return a slice starting cnt bytes
further into the underlying buffer.
Sourcepub fn into_bytes_mut(self, advance: Option<usize>) -> BytesMut
pub fn into_bytes_mut(self, advance: Option<usize>) -> BytesMut
Sourcepub fn into_bytes(self, advance: Option<usize>) -> Bytes
pub fn into_bytes(self, advance: Option<usize>) -> Bytes
Sourcepub fn chunk(&self) -> &[u8] ⓘ
pub fn chunk(&self) -> &[u8] ⓘ
Returns a slice starting at the current position and of length between 0
and ReadBuf::remaining(). Note that this can return shorter slice (this allows
non-continuous internal representation).
Auto Trait Implementations§
impl Freeze for ReadBuf
impl RefUnwindSafe for ReadBuf
impl Send for ReadBuf
impl Sync for ReadBuf
impl Unpin for ReadBuf
impl UnwindSafe for ReadBuf
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more