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§
Required Methods§
Sourcefn on_line<'a>(
&'a mut self,
line: Cow<'a, str>,
) -> impl Future<Output = Next> + Send + 'a
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.
Sourcefn into_output(self) -> Self::Output
fn into_output(self) -> Self::Output
Consumes the sink and returns its final output.
Provided Methods§
Sourcefn on_gap(&mut self)
fn on_gap(&mut self)
Synchronous gap hook; default no-op. See LineSink::on_gap.
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.