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 a Vec<LogEntry> containing zero, one, or two complete entries:
- Zero entries: continuation line for an in-progress multi-line entry, or a headerless line discarded with a warning.
- One entry: either a multi-line entry being flushed by a new single-line entry’s arrival, or a single-line entry emitted alone when no prior entry was in progress.
- Two entries: a multi-line entry being flushed plus the new single-line entry that triggered the flush, both emitted from one call.
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 (multi-line, date-prefixed) — nothing to flush yet.
assert!(buf.push_line("[UnityCrossThreadLogger]1/1/2025 12:00:00 PM").is_empty());
// Continuation line — still accumulating.
assert!(buf.push_line(r#"{"key": "value"}"#).is_empty());
// A single-line header arrives — flushes the multi-line entry AND
// emits the single-line entry, both in one call.
let entries = buf.push_line("[UnityCrossThreadLogger]STATE CHANGED");
assert_eq!(entries.len(), 2);Implementations§
Source§impl LineBuffer
impl LineBuffer
Sourcepub fn push_line(&mut self, line: &str) -> Vec<LogEntry>
pub fn push_line(&mut self, line: &str) -> Vec<LogEntry>
Feeds a single line into the buffer.
Returns a Vec<LogEntry> containing 0, 1, or 2 complete entries
— see the type-level documentation for the full semantics.
§Header classification
When line matches a known header pattern, it is classified as either
single-line or multi-line (see module-level docs). Single-line
headers ([UnityCrossThreadLogger]<non-digit>, [ConnectionManager]…,
Matchmaking:…) flush any prior multi-line entry and emit the new
entry in the same call. Multi-line headers
([UnityCrossThreadLogger]<digit>, [Client GRE]…) flush any prior
entry and begin a fresh accumulation.
Metadata lines (DETAILED LOGS: ENABLED / DISABLED) are
self-contained — treated as single-line entries that flush any prior
in-progress entry alongside themselves.
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.
§Input contract
Callers must strip any trailing \r (Windows CRLF) before invoking
this method. crate::log::tailer::FileTailer::poll already does
this; direct callers in tests must do the same to keep classification
well-defined.
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 multi-line entry, if any. Single-line
entries are never buffered — they are emitted by [push_line] in the
same call that received them — so this method only ever returns at
most one entry.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the buffer, discarding any in-progress entry.
Useful on file rotation when the previous partial entry should be abandoned. Also re-arms the orphan-warning flag so the first post-rotation orphan still surfaces a warning (the rotation case the warning was originally meant to detect).