Skip to content

Commit ed24801

Browse files
committed
Use internal scan state in Results implementation
1 parent 38de0bf commit ed24801

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Diff for: src/result/from_stream.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ where
2121
// if a failure occurs
2222
let mut found_error = None;
2323
let out: V = stream
24-
.scan((), |(), elem| {
24+
.scan(&mut found_error, |error, elem| {
2525
match elem {
2626
Ok(elem) => Some(elem),
2727
Err(err) => {
28-
found_error = Some(err);
28+
**error = Some(err);
2929
// Stop processing the stream on error
3030
None
3131
}

Diff for: src/result/product.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ where
4343
// Using `scan` here because it is able to stop the stream early
4444
// if a failure occurs
4545
let mut found_error = None;
46-
let out = <T as Product<U>>::product(stream.scan((), |(), elem| {
46+
let out = <T as Product<U>>::product(stream.scan(&mut found_error, |error, elem| {
4747
match elem {
4848
Ok(elem) => Some(elem),
4949
Err(err) => {
50-
found_error = Some(err);
50+
**error = Some(err);
5151
// Stop processing the stream on error
5252
None
5353
}

Diff for: src/result/sum.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ where
4343
// Using `scan` here because it is able to stop the stream early
4444
// if a failure occurs
4545
let mut found_error = None;
46-
let out = <T as Sum<U>>::sum(stream.scan((), |(), elem| {
46+
let out = <T as Sum<U>>::sum(stream.scan(&mut found_error, |error, elem| {
4747
match elem {
4848
Ok(elem) => Some(elem),
4949
Err(err) => {
50-
found_error = Some(err);
50+
**error = Some(err);
5151
// Stop processing the stream on error
5252
None
5353
}

0 commit comments

Comments
 (0)