pub struct AsyncParser<'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> AsyncParser<'r, Parser>
impl<'r, Parser: LogParser> AsyncParser<'r, Parser>
Sourcepub fn take_parser(self) -> Parser
pub fn take_parser(self) -> Parser
Get the current parser state.
Sourcepub fn reader_state(&self) -> ReaderState
pub fn reader_state(&self) -> ReaderState
Get the current reader progress.
Sourcepub async fn process_until<T>(
&mut self,
predicate: impl FnMut(&Parser, ReaderState) -> Option<T>,
) -> ParseState<T>
pub async 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].
Sourcepub async fn process_until_every<T>(
&mut self,
predicate: impl FnMut(&Parser, ReaderState) -> Option<T>,
lines_per_check: usize,
) -> ParseState<T>
pub async 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.
Sourcepub async fn process_check_every<T>(
&mut self,
delta: Duration,
predicate: impl FnMut(&Parser, ReaderState) -> Option<T>,
) -> ParseState<T>
pub async 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.
Sourcepub async fn process_all(self) -> FResult<Parser>
pub async 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.
Sourcepub async fn process_all_timeout(
self,
timeout: Duration,
) -> (ParseState<()>, Parser)
pub async 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.
Sourcepub async fn process_all_limit(
self,
bytes: Option<usize>,
lines: Option<usize>,
) -> (ParseState<()>, Parser)
pub async 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: AsyncBufRead + Unpin + 'r> From<R> for AsyncParser<'r, Parser>
impl<'r, Parser: LogParser, R: AsyncBufRead + Unpin + 'r> From<R> for AsyncParser<'r, Parser>
Auto Trait Implementations§
impl<'r, Parser> Freeze for AsyncParser<'r, Parser>where
Parser: Freeze,
impl<'r, Parser> !RefUnwindSafe for AsyncParser<'r, Parser>
impl<'r, Parser> !Send for AsyncParser<'r, Parser>
impl<'r, Parser> !Sync for AsyncParser<'r, Parser>
impl<'r, Parser> Unpin for AsyncParser<'r, Parser>where
Parser: Unpin,
impl<'r, Parser> !UnwindSafe for AsyncParser<'r, Parser>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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