pub trait ShrinkBuffer: FragmentedBuffer {
// Required methods
fn shrink_front(&mut self, n: usize);
fn shrink_back(&mut self, n: usize);
// Provided methods
fn shrink_front_to(&mut self, len: usize) { ... }
fn shrink_back_to(&mut self, len: usize) { ... }
fn shrink<R: RangeBounds<usize>>(&mut self, range: R) { ... }
}
Expand description
A buffer that can reduce its size.
A ShrinkBuffer
is a buffer that can be reduced in size without the
guarantee that the prefix or suffix will be retained. This is typically
sufficient for parsing, but not for serialization.
§Notable implementations
ShrinkBuffer
is implemented for byte slices - &[u8]
and &mut [u8]
.
These types do not implement GrowBuffer
; once bytes are consumed from
their bodies, those bytes are discarded and cannot be recovered.
Required Methods§
Sourcefn shrink_front(&mut self, n: usize)
fn shrink_front(&mut self, n: usize)
Shrinks the front of the body towards the end of the buffer.
shrink_front
consumes the n
left-most bytes of the body, and adds
them to the prefix.
§Panics
Panics if n
is larger than the body.
Sourcefn shrink_back(&mut self, n: usize)
fn shrink_back(&mut self, n: usize)
Shrinks the back of the body towards the beginning of the buffer.
shrink_back
consumes the n
right-most bytes of the body, and adds
them to the suffix.
§Panics
Panics if n
is larger than the body.
Provided Methods§
Sourcefn shrink_front_to(&mut self, len: usize)
fn shrink_front_to(&mut self, len: usize)
Shrinks the buffer to be no larger than len
bytes, consuming from the
front.
shrink_front_to
consumes as many of the left-most bytes of the body as
necessary to ensure that the buffer is no longer than len
bytes. It
adds any bytes consumed to the prefix. If the body is already not longer
than len
bytes, shrink_front_to
does nothing.
Sourcefn shrink_back_to(&mut self, len: usize)
fn shrink_back_to(&mut self, len: usize)
Shrinks the buffer to be no larger than len
bytes, consuming from the
back.
shrink_back_to
consumes as many of the right-most bytes of the body as
necessary to ensure that the buffer is no longer than len
bytes.
It adds any bytes consumed to the suffix. If the body is already no
longer than len
bytes, shrink_back_to
does nothing.
Sourcefn shrink<R: RangeBounds<usize>>(&mut self, range: R)
fn shrink<R: RangeBounds<usize>>(&mut self, range: R)
Shrinks the body.
shrink
shrinks the body to be equal to range
of the previous body.
Any bytes preceding the range are added to the prefix, and any bytes
following the range are added to the suffix.
§Panics
Panics if range
is out of bounds of the body, or if the range
is nonsensical (the end precedes the start).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.