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

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

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

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.