Skip to content

Commit

Permalink
Use internal scan state in Results implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
olegnn committed Jan 15, 2020
1 parent 38de0bf commit ed24801
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/result/from_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/result/product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/result/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit ed24801

Please sign in to comment.