|
1 |
| -use crate::future::Future; |
2 |
| -use crate::task::{Context, Poll}; |
3 |
| - |
4 | 1 | use std::marker::PhantomData;
|
5 | 2 | use std::pin::Pin;
|
6 | 3 |
|
7 |
| -#[derive(Debug)] |
8 |
| -pub struct AllFuture<'a, S, F, T> |
9 |
| -where |
10 |
| - F: FnMut(T) -> bool, |
11 |
| -{ |
| 4 | +use crate::future::Future; |
| 5 | +use crate::stream::Stream; |
| 6 | +use crate::task::{Context, Poll}; |
| 7 | + |
| 8 | +#[doc(hidden)] |
| 9 | +#[allow(missing_debug_implementations)] |
| 10 | +pub struct AllFuture<'a, S, F, T> { |
12 | 11 | pub(crate) stream: &'a mut S,
|
13 | 12 | pub(crate) f: F,
|
14 | 13 | pub(crate) result: bool,
|
15 |
| - pub(crate) __item: PhantomData<T>, |
| 14 | + pub(crate) _marker: PhantomData<T>, |
16 | 15 | }
|
17 | 16 |
|
18 |
| -impl<'a, S, F, T> AllFuture<'a, S, F, T> |
19 |
| -where |
20 |
| - F: FnMut(T) -> bool, |
21 |
| -{ |
22 |
| - pin_utils::unsafe_pinned!(stream: &'a mut S); |
23 |
| - pin_utils::unsafe_unpinned!(result: bool); |
24 |
| - pin_utils::unsafe_unpinned!(f: F); |
25 |
| -} |
| 17 | +impl<S: Unpin, F, T> Unpin for AllFuture<'_, S, F, T> {} |
26 | 18 |
|
27 | 19 | impl<S, F> Future for AllFuture<'_, S, F, S::Item>
|
28 | 20 | where
|
29 |
| - S: futures_core::stream::Stream + Unpin + Sized, |
| 21 | + S: Stream + Unpin + Sized, |
30 | 22 | F: FnMut(S::Item) -> bool,
|
31 | 23 | {
|
32 | 24 | type Output = bool;
|
33 | 25 |
|
34 | 26 | fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
35 |
| - use futures_core::stream::Stream; |
36 |
| - let next = futures_core::ready!(self.as_mut().stream().poll_next(cx)); |
| 27 | + let next = futures_core::ready!(Pin::new(&mut *self.stream).poll_next(cx)); |
| 28 | + |
37 | 29 | match next {
|
38 | 30 | Some(v) => {
|
39 |
| - let result = (self.as_mut().f())(v); |
40 |
| - *self.as_mut().result() = result; |
| 31 | + let result = (&mut self.f)(v); |
| 32 | + self.result = result; |
| 33 | + |
41 | 34 | if result {
|
42 | 35 | // don't forget to wake this task again to pull the next item from stream
|
43 | 36 | cx.waker().wake_by_ref();
|
|
0 commit comments