Struct netstack3_core::tcp::RingBuffer
source · pub struct RingBuffer { /* private fields */ }
Expand description
A circular buffer implementation.
A RingBuffer
holds a logically contiguous ring of memory in three
regions:
- readable: memory is available for reading and not for writing,
- writable: memory that is available for writing and not for reading,
- reserved: memory that was read from and is no longer available for reading or for writing.
Zero or more of these regions can be empty, and a region of memory can transition from one to another in a few different ways:
Readable memory, once read, becomes writable unless a shrink operation is in progress, in which case it becomes reserved.
Writable memory, once marked as such, becomes readable.
Reserved memory will never become readable or writable, and is non-empty only while a shrink is in progress. Once the reserved segment is large enough it will be removed to complete the shrinking.
Implementations§
source§impl RingBuffer
impl RingBuffer
sourcepub fn read_with<F>(&mut self, f: F) -> usize
pub fn read_with<F>(&mut self, f: F) -> usize
Calls f
with contiguous sequences of readable bytes in the buffer and
discards the amount of bytes returned by f
.
§Panics
Panics if the closure wants to discard more bytes than possible, i.e.,
the value returned by f
is greater than self.len()
.
sourcepub fn writable_regions(&mut self) -> impl IntoIterator<Item = &mut [u8]>
pub fn writable_regions(&mut self) -> impl IntoIterator<Item = &mut [u8]>
Returns the writable regions of the RingBuffer
.
sourcepub fn set_target_size(&mut self, new_capacity: usize)
pub fn set_target_size(&mut self, new_capacity: usize)
Sets the target size for the RingBuffer
.
Calling this must not cause the buffer to drop any data. If the new size can be accommodated immediately, it will be applied. Otherwise the buffer will be resized opportunistically during future operatins.
Trait Implementations§
source§impl Buffer for RingBuffer
impl Buffer for RingBuffer
source§fn limits(&self) -> BufferLimits
fn limits(&self) -> BufferLimits
source§fn target_capacity(&self) -> usize
fn target_capacity(&self) -> usize
source§fn request_capacity(&mut self, size: usize)
fn request_capacity(&mut self, size: usize)
source§impl Clone for RingBuffer
impl Clone for RingBuffer
source§fn clone(&self) -> RingBuffer
fn clone(&self) -> RingBuffer
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for RingBuffer
impl Debug for RingBuffer
source§impl Default for RingBuffer
impl Default for RingBuffer
source§impl PartialEq for RingBuffer
impl PartialEq for RingBuffer
source§fn eq(&self, other: &RingBuffer) -> bool
fn eq(&self, other: &RingBuffer) -> bool
self
and other
values to be equal, and is used
by ==
.