pub struct BoundedStream { /* private fields */ }Expand description
A bounded stream backed by a ring buffer.
When writes exceed capacity, the oldest data is evicted to make room. This prevents unbounded memory growth from chatty commands while still keeping recent output available for inspection.
§Example
use kaish_kernel::scheduler::BoundedStream;
let stream = BoundedStream::new(100); // 100 byte max
stream.write(b"hello ").await;
stream.write(b"world").await;
let snapshot = stream.read().await;
assert_eq!(&snapshot, b"hello world");Implementations§
Source§impl BoundedStream
impl BoundedStream
Sourcepub fn new(max_size: usize) -> Self
pub fn new(max_size: usize) -> Self
Create a new bounded stream with the specified maximum size.
Sourcepub fn default_size() -> Self
pub fn default_size() -> Self
Create a new bounded stream with the default max size (10MB).
Sourcepub async fn write(&self, data: &[u8])
pub async fn write(&self, data: &[u8])
Write data to the stream.
If the write would exceed capacity, the oldest data is evicted first. Writing to a closed stream is silently ignored.
Sourcepub async fn read(&self) -> Vec<u8> ⓘ
pub async fn read(&self) -> Vec<u8> ⓘ
Read a snapshot of the current buffer contents.
Returns a copy of all data currently in the buffer. The buffer is not modified.
Sourcepub async fn read_string(&self) -> String
pub async fn read_string(&self) -> String
Read the current buffer as a string (lossy UTF-8 conversion).
Sourcepub async fn close(&self)
pub async fn close(&self)
Close the stream, indicating no more writes are expected.
Subsequent writes will be silently ignored.
Sourcepub async fn stats(&self) -> StreamStats
pub async fn stats(&self) -> StreamStats
Get stream statistics.
Trait Implementations§
Source§impl Clone for BoundedStream
impl Clone for BoundedStream
Source§fn clone(&self) -> BoundedStream
fn clone(&self) -> BoundedStream
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more