Trait ByteBuffer
pub trait ByteBuffer: Sink {
// Required methods
fn clear(&mut self);
fn consume(&mut self, n: usize);
fn filled(&self) -> &[u8] ⓘ;
fn truncate(&mut self, len: usize);
}Expand description
Contiguous byte storage shared by PacketReader and
PacketWriter.
A buffer stores a contiguous run of live bytes. Both sides append through
Sink::put and drain from the front with consume.
Keeping storage behind this trait lets the framer work without allocation.
ArrayBuffer is a fixed-capacity, no_std buffer, while GrowBuffer
grows on the heap when alloc is available.
Implementors must keep the live bytes contiguous so a whole packet can be decoded from one borrowed slice without copying.
Required Methods§
fn clear(&mut self)
fn clear(&mut self)
Drops all buffered bytes.
Call this when a connection is lost so a stale partial packet from the dead connection cannot corrupt framing on the next one.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl ByteBuffer for GrowBuffer
Available on crate feature
alloc only.