Skip to main content

AsyncChunkCollector

Trait AsyncChunkCollector 

Source
pub trait AsyncChunkCollector<S: Sink>: Send + 'static {
    // Required method
    fn collect<'a>(
        &'a mut self,
        chunk: Chunk,
        sink: &'a mut S,
    ) -> impl Future<Output = Next> + Send + 'a;
}
Expand description

An async collector for raw output chunks.

The collector itself may hold state via &mut self, but only the sink S is returned from Consumer::wait or Consumer::cancel.

This trait-based API avoids allocating a boxed future for every collected item while still letting the returned future borrow chunk and sink across .await.

This uses a trait rather than std::ops::AsyncFn because stable Rust can express the lending async callback shape, but cannot yet express the Send bound required on an AsyncFn callback’s returned future for use inside tokio::spawn.

Required Methods§

Source

fn collect<'a>( &'a mut self, chunk: Chunk, sink: &'a mut S, ) -> impl Future<Output = Next> + Send + 'a

Collect a single chunk into sink.

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§