Struct GrowBuffer
pub struct GrowBuffer {
buf: Vec<u8>,
head: usize,
spare: 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 reservation, so draining
many packets out of one read does not repeatedly shift the tail. It never
returns CapacityExceeded; per-packet bounds come from the reader’s or
writer’s set_max_packet_size instead.
Fields§
§buf: Vec<u8>§head: usizeOffset of the first unconsumed byte.
spare: usizeLength of the tail region handed out by the last
spare and not yet committed.
Implementations§
§impl GrowBuffer
impl GrowBuffer
pub const fn new() -> Self
pub const fn new() -> Self
Creates an empty buffer.
pub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty buffer preallocating capacity bytes.
pub fn take(&mut self) -> Vec<u8>
pub fn take(&mut self) -> Vec<u8>
Takes the live bytes as an owned Vec, leaving the buffer empty.
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
Auto Trait Implementations§
impl Freeze for GrowBuffer
impl RefUnwindSafe for GrowBuffer
impl Send for GrowBuffer
impl Sync for GrowBuffer
impl Unpin 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