Trait futures::stream::TryStreamExt [−][src]
pub trait TryStreamExt: TryStream { fn try_collect<C>(self) -> TryCollect<Self, C>
where
C: Default + Extend<Self::Ok>, { ... } }
Adapters specific to Result
-returning streams
Provided Methods
fn try_collect<C>(self) -> TryCollect<Self, C> where
C: Default + Extend<Self::Ok>,
C: Default + Extend<Self::Ok>,
Attempt to Collect all of the values of this stream into a vector, returning a future representing the result of that computation.
This combinator will collect all successful results of this stream and
collect them into a Vec<Self::Item>
. If an error happens then all
collected elements will be dropped and the error will be returned.
The returned future will be resolved when the stream terminates.
This method is only available when the std
feature of this
library is activated, and it is activated by default.
Examples
use std::thread; use futures::prelude::*; use futures::channel::mpsc; use futures::executor::block_on; let (mut tx, rx) = mpsc::unbounded(); thread::spawn(move || { for i in (1..=5) { tx.unbounded_send(Ok(i)).unwrap(); } tx.unbounded_send(Err(6)).unwrap(); }); let output: Result<Vec<i32>, i32> = block_on(rx.try_collect()); assert_eq!(output, Err(6));
Implementors
impl<S> TryStreamExt for S where
S: TryStream,