This commit is contained in:
Sunjay Varma 2019-09-17 16:48:58 -04:00
parent ad0510110c
commit c87dab2d5e
2 changed files with 17 additions and 13 deletions

View file

@ -48,11 +48,11 @@ pub mod io;
pub mod net; pub mod net;
pub mod os; pub mod os;
pub mod prelude; pub mod prelude;
mod result;
pub mod stream; pub mod stream;
pub mod sync; pub mod sync;
pub mod task; pub mod task;
mod vec; mod vec;
mod result;
#[cfg_attr(feature = "docs", doc(cfg(unstable)))] #[cfg_attr(feature = "docs", doc(cfg(unstable)))]
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]

View file

@ -3,7 +3,9 @@ use crate::stream::{FromStream, IntoStream, Stream};
use std::pin::Pin; use std::pin::Pin;
impl<T: Send, E: Send, V> FromStream<Result<T, E>> for Result<V, E> impl<T: Send, E: Send, V> FromStream<Result<T, E>> for Result<V, E>
where V: FromStream<T> { where
V: FromStream<T>,
{
/// Takes each element in the stream: if it is an `Err`, no further /// Takes each element in the stream: if it is an `Err`, no further
/// elements are taken, and the `Err` is returned. Should no `Err` /// elements are taken, and the `Err` is returned. Should no `Err`
/// occur, a container with the values of each `Result` is returned. /// occur, a container with the values of each `Result` is returned.
@ -22,16 +24,19 @@ impl<T: Send, E: Send, V> FromStream<Result<T, E>> for Result<V, E>
// Using `scan` here because it is able to stop the stream early // Using `scan` here because it is able to stop the stream early
// if a failure occurs // if a failure occurs
let mut found_error = None; let mut found_error = None;
let out: V = stream.scan((), |_, elem| { let out: V = stream
match elem { .scan((), |_, elem| {
Ok(elem) => Some(elem), match elem {
Err(err) => { Ok(elem) => Some(elem),
found_error = Some(err); Err(err) => {
// Stop processing the stream on error found_error = Some(err);
None // Stop processing the stream on error
}, None
} }
}).collect().await; }
})
.collect()
.await;
match found_error { match found_error {
Some(err) => Err(err), Some(err) => Err(err),
@ -40,4 +45,3 @@ impl<T: Send, E: Send, V> FromStream<Result<T, E>> for Result<V, E>
})) }))
} }
} }