Skip to content

Commit 8a4add3

Browse files
taiki-ecramertj
authored andcommitted
impl FusedStream for stream::{Empty, Pending} (#1693)
impl FusedStream for stream::{Empty, Pending} Pending is never returning Poll::Ready.
1 parent efcae3b commit 8a4add3

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

futures-util/src/future/pending.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Pending<T> {
1212

1313
impl<T> FusedFuture for Pending<T> {
1414
fn is_terminated(&self) -> bool {
15-
false
15+
true
1616
}
1717
}
1818

futures-util/src/stream/empty.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::marker::PhantomData;
22
use core::pin::Pin;
3-
use futures_core::stream::Stream;
3+
use futures_core::stream::{FusedStream, Stream};
44
use futures_core::task::{Context, Poll};
55

66
/// Stream for the [`empty`] function.
@@ -21,6 +21,12 @@ pub fn empty<T>() -> Empty<T> {
2121

2222
impl<T> Unpin for Empty<T> {}
2323

24+
impl<T> FusedStream for Empty<T> {
25+
fn is_terminated(&self) -> bool {
26+
true
27+
}
28+
}
29+
2430
impl<T> Stream for Empty<T> {
2531
type Item = T;
2632

futures-util/src/stream/pending.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use core::marker;
22
use core::pin::Pin;
3-
4-
use futures_core::{Stream, Poll};
5-
use futures_core::task;
3+
use futures_core::stream::{FusedStream, Stream};
4+
use futures_core::task::{Context, Poll};
65

76
/// Stream for the [`pending()`] function.
87
#[derive(Debug)]
@@ -18,10 +17,16 @@ pub fn pending<T>() -> Pending<T> {
1817
Pending { _data: marker::PhantomData }
1918
}
2019

20+
impl<T> FusedStream for Pending<T> {
21+
fn is_terminated(&self) -> bool {
22+
true
23+
}
24+
}
25+
2126
impl<T> Stream for Pending<T> {
2227
type Item = T;
2328

24-
fn poll_next(self: Pin<&mut Self>, _: &mut task::Context<'_>) -> Poll<Option<Self::Item>> {
29+
fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<Self::Item>> {
2530
Poll::Pending
2631
}
2732
}

0 commit comments

Comments
 (0)