Skip to main content

LineBuffer

Struct LineBuffer 

Source
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

Source

pub fn new() -> Self

Creates a new, empty line buffer with the compiled header regex.

Source

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.

Source

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.

Source

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).

Source

pub fn is_empty(&self) -> bool

Returns true if no entry is currently being accumulated.

Trait Implementations§

Source§

impl Default for LineBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.