From ec5415358f929a5ce92f7451503653c7a190893e Mon Sep 17 00:00:00 2001 From: laizy Date: Fri, 22 Nov 2019 01:03:23 +0800 Subject: [PATCH] simplify AllFuture and AnyFuture (#572) --- src/stream/stream/all.rs | 5 +---- src/stream/stream/any.rs | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/stream/stream/all.rs b/src/stream/stream/all.rs index 5adb68f..d2ac5ca 100644 --- a/src/stream/stream/all.rs +++ b/src/stream/stream/all.rs @@ -10,7 +10,6 @@ use crate::task::{Context, Poll}; pub struct AllFuture<'a, S, F, T> { pub(crate) stream: &'a mut S, pub(crate) f: F, - pub(crate) result: bool, pub(crate) _marker: PhantomData, } @@ -19,7 +18,6 @@ impl<'a, S, F, T> AllFuture<'a, S, F, T> { Self { stream, f, - result: true, // the default if the empty stream _marker: PhantomData, } } @@ -40,7 +38,6 @@ where match next { Some(v) => { let result = (&mut self.f)(v); - self.result = result; if result { // don't forget to wake this task again to pull the next item from stream @@ -50,7 +47,7 @@ where Poll::Ready(false) } } - None => Poll::Ready(self.result), + None => Poll::Ready(true), } } } diff --git a/src/stream/stream/any.rs b/src/stream/stream/any.rs index d6853a1..34168e6 100644 --- a/src/stream/stream/any.rs +++ b/src/stream/stream/any.rs @@ -10,7 +10,6 @@ use crate::task::{Context, Poll}; pub struct AnyFuture<'a, S, F, T> { pub(crate) stream: &'a mut S, pub(crate) f: F, - pub(crate) result: bool, pub(crate) _marker: PhantomData, } @@ -19,7 +18,6 @@ impl<'a, S, F, T> AnyFuture<'a, S, F, T> { Self { stream, f, - result: false, // the default if the empty stream _marker: PhantomData, } } @@ -40,7 +38,6 @@ where match next { Some(v) => { let result = (&mut self.f)(v); - self.result = result; if result { Poll::Ready(true) @@ -50,7 +47,7 @@ where Poll::Pending } } - None => Poll::Ready(self.result), + None => Poll::Ready(false), } } }