pub struct LogBuffer<T: AsRef<[u8]> + AsMut<[u8]>> { /* private fields */ }Expand description
A ring buffer that stores UTF-8 text.
Anything that implements AsMut<[u8]> can be used for backing storage;
e.g. [u8; N], Vec<[u8]>, Box<[u8]>.
Implementations§
Source§impl<T: AsRef<[u8]> + AsMut<[u8]>> LogBuffer<T>
impl<T: AsRef<[u8]> + AsMut<[u8]>> LogBuffer<T>
Sourcepub fn new(storage: T) -> LogBuffer<T>
pub fn new(storage: T) -> LogBuffer<T>
Creates a new ring buffer, backed by storage.
The buffer is cleared after creation.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the buffer.
Only the text written after clearing will be read out by a future extraction.
This function takes O(n) time where n is buffer length.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks whether the ring buffer is empty.
This function takes O(1) time.
Sourcepub fn extract(&mut self) -> &str
pub fn extract(&mut self) -> &str
Extracts the contents of the ring buffer as a string slice, excluding any partially overwritten UTF-8 code unit sequences at the beginning.
Extraction rotates the contents of the ring buffer such that all of its contents becomes contiguous in memory.
This function takes O(n) time where n is buffer length.
Sourcepub fn extract_lines(&mut self) -> Lines<'_>
pub fn extract_lines(&mut self) -> Lines<'_>
Extracts the contents of the ring buffer as an iterator over its lines, excluding any partially overwritten lines at the beginning.
The first line written to the ring buffer after clearing it should start
with '\n', or it will be treated as partially overwritten and lost.
Extraction rotates the contents of the ring buffer such that all of its contents becomes contiguous in memory.
This function takes O(n) time where n is buffer length.