Skip to main content

AsyncLineVisitor

Trait AsyncLineVisitor 

Source
pub trait AsyncLineVisitor: Send + 'static {
    type Output: Send + 'static;

    // Required methods
    fn on_line<'a>(
        &'a mut self,
        line: Cow<'a, str>,
    ) -> impl Future<Output = Next> + Send + 'a;
    fn into_output(self) -> Self::Output;

    // Provided methods
    fn on_gap(&mut self) { ... }
    fn on_eof(&mut self) -> impl Future<Output = ()> + Send + '_ { ... }
}
Expand description

Async per-line action selected by the AsyncStreamVisitor impl of ParseLines.

on_line is async because async per-line work (writing to an async sink, awaiting a channel) needs .await. on_gap stays synchronous because gap notification carries no payload to await on, mirroring AsyncStreamVisitor::on_gap.

§Allocation note

The async path materializes every parsed line as an owned String before handing it to on_line. The synchronous LineVisitor path can instead pass a Cow::Borrowed straight out of the chunk on the fast path, so it avoids a per-line allocation when the line fits in the current chunk. The allocation is the cost of holding the parser’s borrow across an .await, which Rust does not allow because the next iteration re-borrows the parser. Prefer LineVisitor (composed via ParseLines::inspect / ParseLines::collect) when per-line work is non-blocking, and you want the zero-copy fast path; reach for AsyncLineVisitor only when the per-line work genuinely needs to await.

Required Associated Types§

Source

type Output: Send + 'static

Final value produced once the adapter is finished.

Required Methods§

Source

fn on_line<'a>( &'a mut self, line: Cow<'a, str>, ) -> impl Future<Output = Next> + Send + 'a

Asynchronously observes a single parsed line. Return Next::Break to stop further parsing.

Source

fn into_output(self) -> Self::Output

Consumes the sink and returns its final output.

Provided Methods§

Source

fn on_gap(&mut self)

Synchronous gap hook; default no-op. See LineVisitor::on_gap.

Source

fn on_eof(&mut self) -> impl Future<Output = ()> + Send + '_

Asynchronous EOF hook; default no-op. Invoked after the adapter has flushed any trailing line through on_line.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

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

Source§

impl<T, F> AsyncLineVisitor for 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§

impl<W, H, F, B> AsyncLineVisitor for WriteLines<W, H, F, B>
where W: Sink + AsyncWriteExt + Unpin, H: SinkWriteErrorHandler, B: AsRef<[u8]> + Send + 'static, F: Fn(Cow<'_, str>) -> B + Send + Sync + 'static,