Skip to main content

ParseLines

Struct ParseLines 

Source
pub struct ParseLines<S> { /* private fields */ }
Expand description

Adapter that drives a LineParser over chunk events and dispatches every emitted line to the inner LineVisitor (sync) or AsyncLineVisitor (async).

Implements StreamVisitor when S: LineVisitor and AsyncStreamVisitor when S: AsyncLineVisitor.

Implementations§

Source§

impl<S> ParseLines<S>

Source

pub fn new(options: LineParsingOptions, inner: S) -> Self

Creates a new line adapter.

§Panics

Panics if options.max_line_length is zero. See LineParsingOptions::max_line_length for the rationale; pass crate::NumBytes::MAX for effectively-unbounded line parsing.

Source§

impl<F> ParseLines<InspectLines<F>>
where F: FnMut(Cow<'_, str>) -> Next + Send + 'static,

Source

pub fn inspect(options: LineParsingOptions, f: F) -> Self

Convenience constructor: wraps f in an InspectLines and composes it with this adapter. Equivalent to ParseLines::new(options, InspectLines::new(f)).

§Panics

Panics if options.max_line_length is zero.

Source§

impl<F, Fut> ParseLines<InspectLinesAsync<F, Fut>>
where F: FnMut(Cow<'_, str>) -> Fut + Send + 'static, Fut: Future<Output = Next> + Send + 'static,

Source

pub fn inspect_async(options: LineParsingOptions, f: F) -> Self

Convenience constructor: wraps f in an InspectLinesAsync and composes it with this adapter. Equivalent to ParseLines::new(options, InspectLinesAsync::new(f)).

§Panics

Panics if options.max_line_length is zero.

Source§

impl<T, F> ParseLines<CollectLines<T, F>>
where T: Sink, F: FnMut(Cow<'_, str>, &mut T) -> Next + Send + 'static,

Source

pub fn collect(options: LineParsingOptions, sink: T, f: F) -> Self

Convenience constructor: wraps sink and f in a CollectLines and composes it with this adapter.

§Panics

Panics if options.max_line_length is zero.

Source§

impl<T, F> ParseLines<CollectLinesAsync<T, F>>
where T: Sink, F: for<'a> FnMut(Cow<'a, str>, &'a mut T) -> Pin<Box<dyn Future<Output = Next> + Send + 'a>> + Send + 'static,

Source

pub fn collect_async(options: LineParsingOptions, sink: T, f: F) -> Self

Convenience constructor: wraps sink and f in a CollectLinesAsync and composes it with this adapter. The closure must wrap its async body in Box::pin(async move { ... }).

§Panics

Panics if options.max_line_length is zero.

Trait Implementations§

Source§

impl<S: AsyncLineVisitor> AsyncStreamVisitor for ParseLines<S>

Source§

type Output = <S as AsyncLineVisitor>::Output

The value produced by into_output after the visitor has finished observing the stream. Returned via Consumer::wait and Consumer::cancel.
Source§

async fn on_chunk(&mut self, chunk: Chunk) -> Next

Asynchronously observes a single chunk. Read more
Source§

fn on_gap(&mut self)

Invoked when the stream backend reports that one or more chunks were dropped between the last delivered chunk and the next one. Read more
Source§

async fn on_eof(&mut self)

Asynchronously observes end-of-stream. Read more
Source§

fn into_output(self) -> Self::Output

Consumes the visitor and returns its final output. Read more
Source§

impl<S: LineVisitor> StreamVisitor for ParseLines<S>

Source§

type Output = <S as LineVisitor>::Output

The value produced by into_output after the visitor has finished observing the stream. Returned via Consumer::wait and Consumer::cancel.
Source§

fn on_chunk(&mut self, chunk: Chunk) -> Next

Invoked for every chunk observed on the stream. Read more
Source§

fn on_gap(&mut self)

Invoked when the stream backend reports that one or more chunks were dropped between the last delivered chunk and the next one. Read more
Source§

fn on_eof(&mut self)

Invoked exactly once when the stream ends (EOF or write side dropped). Read more
Source§

fn into_output(self) -> Self::Output

Consumes the visitor and returns its final output. Read more

Auto Trait Implementations§

§

impl<S> Freeze for ParseLines<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for ParseLines<S>
where S: RefUnwindSafe,

§

impl<S> Send for ParseLines<S>
where S: Send,

§

impl<S> Sync for ParseLines<S>
where S: Sync,

§

impl<S> Unpin for ParseLines<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for ParseLines<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for ParseLines<S>
where S: UnwindSafe,

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Sink for T
where T: Send + 'static,