Skip to main content

AsyncLineSink

Trait AsyncLineSink 

Source
pub trait AsyncLineSink: 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 LineAdapter.

on_line is async because the line-aware async visitors (inspect_lines_async, collect_lines_async, collect_lines_into_write*) all need to .await per-line work. 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 LineSink 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. Use LineSink (and the corresponding inspect_lines / collect_lines factories) when per-line work is non-blocking and you want the zero-copy fast path; reach for AsyncLineSink 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 LineSink::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> AsyncLineSink for InspectLineSinkAsync<F, Fut>
where F: FnMut(Cow<'_, str>) -> Fut + Send + 'static, Fut: Future<Output = Next> + Send + 'static,

Source§

impl<T, C> AsyncLineSink for CollectLineSinkAsync<T, C>
where T: Sink, C: AsyncLineCollector<T>,

Source§

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