pub struct RingBuffer { /* private fields */ }Expand description
A ring buffer for accumulating terminal output.
The buffer supports efficient append operations and automatically discards oldest data when the maximum size is reached.
Implementations§
Source§impl RingBuffer
impl RingBuffer
Sourcepub fn with_default_capacity() -> Self
pub fn with_default_capacity() -> Self
Create a new ring buffer with default capacity.
Sourcepub fn append(&mut self, data: &[u8])
pub fn append(&mut self, data: &[u8])
Append data to the buffer.
If the buffer would exceed its maximum size, oldest data is discarded.
Sourcepub fn as_slice(&mut self) -> &[u8] ⓘ
pub fn as_slice(&mut self) -> &[u8] ⓘ
Get the current buffer contents as a contiguous slice.
Note: This may need to reallocate if the buffer wraps around.
Sourcepub fn as_str_lossy(&mut self) -> String
pub fn as_str_lossy(&mut self) -> String
Get the current buffer contents as a string (lossy UTF-8 conversion).
Sourcepub const fn total_written(&self) -> usize
pub const fn total_written(&self) -> usize
Get the total bytes written to the buffer.
Sourcepub const fn bytes_discarded(&self) -> usize
pub const fn bytes_discarded(&self) -> usize
Get the number of bytes that have been discarded due to overflow.
Sourcepub fn find(&mut self, needle: &[u8]) -> Option<usize>
pub fn find(&mut self, needle: &[u8]) -> Option<usize>
Find a byte sequence in the buffer.
Returns the position of the first match.
Sourcepub fn consume(&mut self, end: usize) -> Vec<u8> ⓘ
pub fn consume(&mut self, end: usize) -> Vec<u8> ⓘ
Consume data up to and including the specified position.
Returns the consumed data.
Sourcepub fn consume_before(&mut self, pos: usize) -> String
pub fn consume_before(&mut self, pos: usize) -> String
Consume data up to (but not including) the specified position.
Returns the consumed data as a string (lossy conversion).
Sourcepub fn consume_until(&mut self, needle: &str) -> Option<(String, String)>
pub fn consume_until(&mut self, needle: &str) -> Option<(String, String)>
Consume data up to and including a pattern match.
Returns (before_match, matched_text) if found.
Trait Implementations§
Source§impl Clone for RingBuffer
impl Clone for 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 Write for RingBuffer
impl Write for RingBuffer
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)