From ed248017b476f17334260db31daf82cc07c2a465 Mon Sep 17 00:00:00 2001 From: Oleg Nosov Date: Wed, 15 Jan 2020 12:06:50 +0300 Subject: [PATCH] Use internal `scan` state in `Result`s implementation --- src/result/from_stream.rs | 4 ++-- src/result/product.rs | 4 ++-- src/result/sum.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/result/from_stream.rs b/src/result/from_stream.rs index 424a53b..86405ce 100644 --- a/src/result/from_stream.rs +++ b/src/result/from_stream.rs @@ -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 } diff --git a/src/result/product.rs b/src/result/product.rs index ad2e014..89ddacb 100644 --- a/src/result/product.rs +++ b/src/result/product.rs @@ -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 = >::product(stream.scan((), |(), elem| { + let out = >::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 } diff --git a/src/result/sum.rs b/src/result/sum.rs index 1cf5b7a..c0ef4c2 100644 --- a/src/result/sum.rs +++ b/src/result/sum.rs @@ -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 = >::sum(stream.scan((), |(), elem| { + let out = >::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 }