simplify AllFuture and AnyFuture (#572)

pull/561/head
laizy 5 years ago committed by Stjepan Glavina
parent ba1ee2d204
commit ec5415358f

@ -10,7 +10,6 @@ use crate::task::{Context, Poll};
pub struct AllFuture<'a, S, F, T> { pub struct AllFuture<'a, S, F, T> {
pub(crate) stream: &'a mut S, pub(crate) stream: &'a mut S,
pub(crate) f: F, pub(crate) f: F,
pub(crate) result: bool,
pub(crate) _marker: PhantomData<T>, pub(crate) _marker: PhantomData<T>,
} }
@ -19,7 +18,6 @@ impl<'a, S, F, T> AllFuture<'a, S, F, T> {
Self { Self {
stream, stream,
f, f,
result: true, // the default if the empty stream
_marker: PhantomData, _marker: PhantomData,
} }
} }
@ -40,7 +38,6 @@ where
match next { match next {
Some(v) => { Some(v) => {
let result = (&mut self.f)(v); let result = (&mut self.f)(v);
self.result = result;
if result { if result {
// don't forget to wake this task again to pull the next item from stream // don't forget to wake this task again to pull the next item from stream
@ -50,7 +47,7 @@ where
Poll::Ready(false) Poll::Ready(false)
} }
} }
None => Poll::Ready(self.result), None => Poll::Ready(true),
} }
} }
} }

@ -10,7 +10,6 @@ use crate::task::{Context, Poll};
pub struct AnyFuture<'a, S, F, T> { pub struct AnyFuture<'a, S, F, T> {
pub(crate) stream: &'a mut S, pub(crate) stream: &'a mut S,
pub(crate) f: F, pub(crate) f: F,
pub(crate) result: bool,
pub(crate) _marker: PhantomData<T>, pub(crate) _marker: PhantomData<T>,
} }
@ -19,7 +18,6 @@ impl<'a, S, F, T> AnyFuture<'a, S, F, T> {
Self { Self {
stream, stream,
f, f,
result: false, // the default if the empty stream
_marker: PhantomData, _marker: PhantomData,
} }
} }
@ -40,7 +38,6 @@ where
match next { match next {
Some(v) => { Some(v) => {
let result = (&mut self.f)(v); let result = (&mut self.f)(v);
self.result = result;
if result { if result {
Poll::Ready(true) Poll::Ready(true)
@ -50,7 +47,7 @@ where
Poll::Pending Poll::Pending
} }
} }
None => Poll::Ready(self.result), None => Poll::Ready(false),
} }
} }
} }

Loading…
Cancel
Save