|
1 | 1 | use std::pin::Pin; |
| 2 | +use std::task::{Context, Poll}; |
2 | 3 |
|
3 | | -use crate::task::{Context, Poll}; |
4 | | - |
5 | | -/// A `Stream` that is permanently closed |
6 | | -/// once a single call to `poll` results in |
7 | | -/// `Poll::Ready(None)`, returning `Poll::Ready(None)` |
8 | | -/// for all future calls to `poll`. |
| 4 | +/// A `Stream` that is permanently closed once a single call to `poll` results in |
| 5 | +/// `Poll::Ready(None)`, returning `Poll::Ready(None)` for all future calls to `poll`. |
9 | 6 | #[derive(Clone, Debug)] |
10 | 7 | pub struct Fuse<S> { |
11 | | - stream: S, |
12 | | - done: bool, |
| 8 | + pub(crate) stream: S, |
| 9 | + pub(crate) done: bool, |
13 | 10 | } |
14 | 11 |
|
15 | 12 | impl<S: Unpin> Unpin for Fuse<S> {} |
16 | 13 |
|
17 | | -impl<S: futures::Stream> Fuse<S> { |
| 14 | +impl<S: futures_core::Stream> Fuse<S> { |
18 | 15 | pin_utils::unsafe_pinned!(stream: S); |
19 | 16 | pin_utils::unsafe_unpinned!(done: bool); |
20 | | - |
21 | | - /// Returns `true` if the underlying stream is fused. |
22 | | - /// |
23 | | - /// If this `Stream` is fused, all future calls to |
24 | | - /// `poll` will return `Poll::Ready(None)`. |
25 | | - pub fn is_done(&self) -> bool { |
26 | | - self.done |
27 | | - } |
28 | | - |
29 | | - /// Consumes this `Fuse` and returns the inner |
30 | | - /// `Stream`, unfusing it if it had become |
31 | | - /// fused. |
32 | | - pub fn into_inner(self) -> S |
33 | | - where |
34 | | - S: Sized, |
35 | | - { |
36 | | - self.stream |
37 | | - } |
38 | 17 | } |
39 | 18 |
|
40 | | - |
41 | | -impl<S: futures::Stream> futures::Stream for Fuse<S> { |
| 19 | +impl<S: futures_core::Stream> futures_core::Stream for Fuse<S> { |
42 | 20 | type Item = S::Item; |
43 | 21 |
|
44 | 22 | fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<S::Item>> { |
45 | 23 | if self.done { |
46 | 24 | Poll::Ready(None) |
47 | 25 | } else { |
48 | | - let next = futures::ready!(self.as_mut().stream().poll_next(cx)); |
| 26 | + let next = futures_core::ready!(self.as_mut().stream().poll_next(cx)); |
49 | 27 | if next.is_none() { |
50 | 28 | *self.as_mut().done() = true; |
51 | 29 | } |
|
0 commit comments