forked from mirror/async-std
rustfmt
This commit is contained in:
parent
ad0510110c
commit
c87dab2d5e
2 changed files with 17 additions and 13 deletions
|
@ -48,11 +48,11 @@ pub mod io;
|
|||
pub mod net;
|
||||
pub mod os;
|
||||
pub mod prelude;
|
||||
mod result;
|
||||
pub mod stream;
|
||||
pub mod sync;
|
||||
pub mod task;
|
||||
mod vec;
|
||||
mod result;
|
||||
|
||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||
#[cfg(feature = "unstable")]
|
||||
|
|
|
@ -3,7 +3,9 @@ use crate::stream::{FromStream, IntoStream, Stream};
|
|||
use std::pin::Pin;
|
||||
|
||||
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
|
||||
/// elements are taken, and the `Err` is returned. Should no `Err`
|
||||
/// 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
|
||||
// if a failure occurs
|
||||
let mut found_error = None;
|
||||
let out: V = stream.scan((), |_, elem| {
|
||||
let out: V = stream
|
||||
.scan((), |_, elem| {
|
||||
match elem {
|
||||
Ok(elem) => Some(elem),
|
||||
Err(err) => {
|
||||
found_error = Some(err);
|
||||
// Stop processing the stream on error
|
||||
None
|
||||
},
|
||||
}
|
||||
}).collect().await;
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
match found_error {
|
||||
Some(err) => Err(err),
|
||||
|
@ -40,4 +45,3 @@ impl<T: Send, E: Send, V> FromStream<Result<T, E>> for Result<V, E>
|
|||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue