Struct StreamParser

Source
pub struct StreamParser<'r, Parser: LogParser> { /* private fields */ }
Expand description

Struct which contains both a parser state as well as the stream of lines which are being parsed. Always use this instead of the raw underlying parser. Feeds the parser line-by-line with a callback to indicate if or when to pause. Supports any parser as long as it implements LogParser.

Implementations§

Source§

impl<'r, Parser: LogParser> StreamParser<'r, Parser>

Source

pub fn parser(&self) -> &Parser

Get the current parser state.

Source

pub fn take_parser(self) -> Parser

Get the current parser state.

Source

pub fn reader_state(&self) -> ReaderState

Get the current reader progress.

Source

pub fn is_done(&self) -> bool

Have we finished parsing?

Source

pub fn process_until<T>( &mut self, predicate: impl FnMut(&Parser, ReaderState) -> Option<T>, ) -> ParseState<T>

Parse the the input while calling the predicate callback after each line. Keep parsing until the callback returns Some(t) or we reach the end of the input. If we stopped due to the callback, return the current progress as ParseState::Paused(t, state). After this function returns, use parser to retrieve the parser state.

The predicate callback should aim to return quickly since it is called between each line! If heavier processing is required consider using [process_check_every] or [process_until_every].

Source

pub fn process_until_every<T>( &mut self, predicate: impl FnMut(&Parser, ReaderState) -> Option<T>, lines_per_check: usize, ) -> ParseState<T>

Identical to [process_until] except the predicate is only checked every lines_per_check lines.

Source

pub fn process_check_every<T>( &mut self, delta: Duration, predicate: impl FnMut(&Parser, ReaderState) -> Option<T>, ) -> ParseState<T>

Parse the the input while calling the predicate callback every delta time. Keep parsing until the callback returns Some(t) or we reach the end of the input. If we stopped due to the callback, return the current progress as ParseState::Paused(t, state). After this function returns, use parser to retrieve the parser state.

Source

pub fn process_all(self) -> FResult<Parser>

Parse the entire file as a stream. Using [process_all_timeout] instead is recommended as this method will cause the process to hang if given a very large file.

Source

pub fn process_all_timeout(self, timeout: Duration) -> (ParseState<()>, Parser)

Try to parse everything, but stop after a given timeout. The result tuple contains ParseState::Paused(read_info) if the timeout was reached, and the parser state at the end (i.e. the state is complete only if ParseState::Completed was returned).

Parsing cannot be resumed if the timeout is reached. If you need support for resuming, use [process_check_every] or [process_until] instead.

Source

pub fn process_all_limit( self, bytes: Option<usize>, lines: Option<usize>, ) -> (ParseState<()>, Parser)

Try to parse everything, but stop after parsing bytes bytes or lines lines (whichever comes first). The limit is ignored when set to None (i.e. if both are None this is identical to process_all). The result tuple contains ParseState::Paused(read_info) if the limit was reached, and the parser state at the end (i.e. the state is complete only if ParseState::Completed was returned).

Parsing cannot be resumed if the limit is reached. If you need support for resuming, use [process_until] instead.

Trait Implementations§

Source§

impl<'r, Parser: LogParser, R: BufRead + 'r> From<R> for StreamParser<'r, Parser>

Source§

fn from(reader: R) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'r, Parser> Freeze for StreamParser<'r, Parser>
where Parser: Freeze,

§

impl<'r, Parser> !RefUnwindSafe for StreamParser<'r, Parser>

§

impl<'r, Parser> !Send for StreamParser<'r, Parser>

§

impl<'r, Parser> !Sync for StreamParser<'r, Parser>

§

impl<'r, Parser> Unpin for StreamParser<'r, Parser>
where Parser: Unpin,

§

impl<'r, Parser> !UnwindSafe for StreamParser<'r, Parser>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.