pub struct LineBuffer { /* private fields */ }Expand description
Accumulates raw lines and produces complete LogEntry values when a
new header boundary is detected.
§Usage
Feed lines one at a time via push_line. Each call
returns Some(LogEntry) when a new header flushes the previous entry.
After the input stream ends (EOF or file rotation), call
flush to retrieve any remaining buffered entry.
§Example
use manasight_parser::log::entry::LineBuffer;
let mut buf = LineBuffer::new();
// First header — nothing to flush yet.
assert!(buf.push_line("[UnityCrossThreadLogger] 1/1/2025 Event1").is_none());
// Continuation line — still accumulating.
assert!(buf.push_line(r#"{"key": "value"}"#).is_none());
// Second header — flushes the first entry.
if let Some(entry) = buf.push_line("[Client GRE] 1/1/2025 Event2") {
assert_eq!(entry.body, "[UnityCrossThreadLogger] 1/1/2025 Event1\n{\"key\": \"value\"}");
}
// Flush the remaining entry.
if let Some(last) = buf.flush() {
assert_eq!(last.body, "[Client GRE] 1/1/2025 Event2");
}Implementations§
Source§impl LineBuffer
impl LineBuffer
Sourcepub fn push_line(&mut self, line: &str) -> Option<LogEntry>
pub fn push_line(&mut self, line: &str) -> Option<LogEntry>
Feeds a single line into the buffer.
Returns Some(LogEntry) when line starts a new log entry header,
flushing the previously accumulated entry. Returns None when the
line is a continuation of the current entry, or when no entry was
in progress (buffer was empty).
Metadata lines (DETAILED LOGS: ENABLED / DISABLED) are treated
as self-contained entries: the current in-progress entry (if any) is
flushed, the metadata entry is returned, and no new accumulation
begins. If a metadata line is the first line in the stream (nothing
to flush), it is returned directly.
Lines that arrive before any header has been seen are discarded with a warning log — this handles partial entries at the start of a file or after rotation.
Sourcepub fn flush(&mut self) -> Option<LogEntry>
pub fn flush(&mut self) -> Option<LogEntry>
Flushes any remaining buffered entry.
Call this when the input stream ends (EOF or file rotation) to retrieve the last accumulated entry.