Use internal `scan` state in `Result`s implementation

split-by-pattern
Oleg Nosov 5 years ago
parent 38de0bfd22
commit ed248017b4
No known key found for this signature in database
GPG Key ID: DE90B83800644E24

@ -21,11 +21,11 @@ where
// if a failure occurs
let mut found_error = None;
let out: V = stream
.scan((), |(), elem| {
.scan(&mut found_error, |error, elem| {
match elem {
Ok(elem) => Some(elem),
Err(err) => {
found_error = Some(err);
**error = Some(err);
// Stop processing the stream on error
None
}

@ -43,11 +43,11 @@ where
// Using `scan` here because it is able to stop the stream early
// if a failure occurs
let mut found_error = None;
let out = <T as Product<U>>::product(stream.scan((), |(), elem| {
let out = <T as Product<U>>::product(stream.scan(&mut found_error, |error, elem| {
match elem {
Ok(elem) => Some(elem),
Err(err) => {
found_error = Some(err);
**error = Some(err);
// Stop processing the stream on error
None
}

@ -43,11 +43,11 @@ where
// Using `scan` here because it is able to stop the stream early
// if a failure occurs
let mut found_error = None;
let out = <T as Sum<U>>::sum(stream.scan((), |(), elem| {
let out = <T as Sum<U>>::sum(stream.scan(&mut found_error, |error, elem| {
match elem {
Ok(elem) => Some(elem),
Err(err) => {
found_error = Some(err);
**error = Some(err);
// Stop processing the stream on error
None
}

Loading…
Cancel
Save