|
|
@ -1,7 +1,7 @@
|
|
|
|
use std::pin::Pin;
|
|
|
|
use std::pin::Pin;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::prelude::*;
|
|
|
|
use crate::prelude::*;
|
|
|
|
use crate::stream::{Stream, Product};
|
|
|
|
use crate::stream::{Product, Stream};
|
|
|
|
|
|
|
|
|
|
|
|
impl<T, U, E> Product<Result<U, E>> for Result<T, E>
|
|
|
|
impl<T, U, E> Product<Result<U, E>> for Result<T, E>
|
|
|
|
where
|
|
|
|
where
|
|
|
@ -36,14 +36,14 @@ where
|
|
|
|
```
|
|
|
|
```
|
|
|
|
"#]
|
|
|
|
"#]
|
|
|
|
fn product<'a, S>(stream: S) -> Pin<Box<dyn Future<Output = Result<T, E>> + 'a>>
|
|
|
|
fn product<'a, S>(stream: S) -> Pin<Box<dyn Future<Output = Result<T, E>> + 'a>>
|
|
|
|
where S: Stream<Item = Result<U, E>> + 'a
|
|
|
|
where
|
|
|
|
|
|
|
|
S: Stream<Item = Result<U, E>> + 'a,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Box::pin(async move {
|
|
|
|
Box::pin(async move {
|
|
|
|
// 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 = <T as Product<U>>::product(stream
|
|
|
|
let out = <T as Product<U>>::product(stream.scan((), |(), elem| {
|
|
|
|
.scan((), |_, elem| {
|
|
|
|
|
|
|
|
match elem {
|
|
|
|
match elem {
|
|
|
|
Ok(elem) => Some(elem),
|
|
|
|
Ok(elem) => Some(elem),
|
|
|
|
Err(err) => {
|
|
|
|
Err(err) => {
|
|
|
@ -52,10 +52,12 @@ where
|
|
|
|
None
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})).await;
|
|
|
|
}))
|
|
|
|
|
|
|
|
.await;
|
|
|
|
|
|
|
|
|
|
|
|
match found_error {
|
|
|
|
match found_error {
|
|
|
|
Some(err) => Err(err),
|
|
|
|
Some(err) => Err(err),
|
|
|
|
None => Ok(out)
|
|
|
|
None => Ok(out),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|