pub struct CollectChunksAsync<T, F>where
T: Sink,
F: for<'a> FnMut(Chunk, &'a mut T) -> Pin<Box<dyn Future<Output = Next> + Send + 'a>> + Send + 'static,{ /* private fields */ }Expand description
Asynchronous counterpart to CollectChunks. The per-chunk hook is a closure that returns a
boxed future, allowing the future to borrow chunk and sink across .await while remaining
Send for tokio::spawn. Construct via fold and pass to
Consumable::consume_async.
The boxed future incurs one allocation per observed chunk; for hot paths that cannot afford
that, implement AsyncStreamVisitor directly on a struct that owns the sink.
§Example
let visitor = CollectChunksAsync::fold(Vec::<u8>::new(), |chunk, sink| {
Box::pin(async move {
sink.extend_from_slice(chunk.as_ref());
Next::Continue
})
});Implementations§
Source§impl<T, F> CollectChunksAsync<T, F>
impl<T, F> CollectChunksAsync<T, F>
Trait Implementations§
Source§impl<T, F> AsyncStreamVisitor for CollectChunksAsync<T, F>
impl<T, F> AsyncStreamVisitor for CollectChunksAsync<T, F>
Source§type Output = T
type Output = T
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) -> impl Future<Output = Next> + Send + '_
fn on_chunk(&mut self, chunk: Chunk) -> impl Future<Output = Next> + Send + '_
Asynchronously observes a single chunk. Read more
Source§fn into_output(self) -> Self::Output
fn into_output(self) -> Self::Output
Consumes the visitor and returns its final output. Read more
Auto Trait Implementations§
impl<T, F> Freeze for CollectChunksAsync<T, F>
impl<T, F> RefUnwindSafe for CollectChunksAsync<T, F>where
T: RefUnwindSafe,
F: RefUnwindSafe,
impl<T, F> Send for CollectChunksAsync<T, F>
impl<T, F> Sync for CollectChunksAsync<T, F>
impl<T, F> Unpin for CollectChunksAsync<T, F>
impl<T, F> UnsafeUnpin for CollectChunksAsync<T, F>where
T: UnsafeUnpin,
F: UnsafeUnpin,
impl<T, F> UnwindSafe for CollectChunksAsync<T, F>where
T: UnwindSafe,
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more