Struct GrowBuffer
pub struct GrowBuffer {
buf: Vec<u8>,
head: usize,
}Available on crate feature
alloc only.Expand description
A heap-backed ByteBuffer that grows as needed.
Consumed bytes are reclaimed lazily on the next append, so draining many
packets out of one read does not repeatedly shift the tail. Appending fails
only if the allocation fails. Per-packet bounds come from the reader’s
set_max_packet_size.
Fields§
§buf: Vec<u8>§head: usizeOffset of the first unconsumed byte.
Implementations§
§impl GrowBuffer
impl GrowBuffer
pub const fn new() -> Self
pub const fn new() -> Self
Creates an empty buffer.
pub fn try_with_capacity(capacity: usize) -> Result<Self, TryReserveError>
pub fn try_with_capacity(capacity: usize) -> Result<Self, TryReserveError>
Creates an empty buffer preallocating capacity bytes.
§Errors
Returns TryReserveError if the allocation fails.
pub fn take(&mut self) -> Vec<u8> ⓘ
pub fn take(&mut self) -> Vec<u8> ⓘ
Takes the live bytes as an owned Vec. The buffer is empty afterwards.
Lets an I/O driver hand a batch of encoded packets to a writer task by value without copying when the consumed prefix is empty.
fn reclaim(&mut self)
Trait Implementations§
§impl ByteBuffer for GrowBuffer
impl ByteBuffer for GrowBuffer
§impl Debug for GrowBuffer
impl Debug for GrowBuffer
§impl Sink for GrowBuffer
impl Sink for GrowBuffer
§type Error = TryReserveError
type Error = TryReserveError
Error returned when the sink cannot take more bytes.
Auto Trait Implementations§
impl Freeze for GrowBuffer
impl RefUnwindSafe for GrowBuffer
impl Send for GrowBuffer
impl Sync for GrowBuffer
impl Unpin for GrowBuffer
impl UnsafeUnpin for GrowBuffer
impl UnwindSafe for GrowBuffer
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