File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -325,6 +325,7 @@ cfg_unstable! {
325325 mod fused_stream;
326326 mod interval;
327327 mod into_stream;
328+ mod pending;
328329 mod product;
329330 mod successors;
330331 mod sum;
@@ -336,6 +337,7 @@ cfg_unstable! {
336337 pub use fused_stream:: FusedStream ;
337338 pub use interval:: { interval, Interval } ;
338339 pub use into_stream:: IntoStream ;
340+ pub use pending:: { pending, Pending } ;
339341 pub use product:: Product ;
340342 pub use stream:: Merge ;
341343 pub use successors:: { successors, Successors } ;
Original file line number Diff line number Diff line change 1+ use std:: marker:: PhantomData ;
2+ use std:: pin:: Pin ;
3+ use std:: task:: { Context , Poll } ;
4+
5+ use crate :: stream:: { Stream , DoubleEndedStream , ExactSizeStream , FusedStream } ;
6+
7+ /// A stream that never returns any items.
8+ ///
9+ /// This stream is created by the [`pending`] function. See its
10+ /// documentation for more.
11+ ///
12+ /// [`pending`]: fn.pending.html
13+ #[ derive( Debug ) ]
14+ pub struct Pending < T > {
15+ _marker : PhantomData < T >
16+ }
17+
18+ /// Creates a stream that never returns any items.
19+ ///
20+ /// The returned stream will always return `Pending` when polled.
21+ pub fn pending < T > ( ) -> Pending < T > {
22+ Pending { _marker : PhantomData }
23+ }
24+
25+ impl < T > Stream for Pending < T > {
26+ type Item = T ;
27+
28+ fn poll_next ( self : Pin < & mut Self > , _: & mut Context < ' _ > ) -> Poll < Option < T > > {
29+ Poll :: Pending
30+ }
31+
32+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
33+ ( 0 , Some ( 0 ) )
34+ }
35+ }
36+
37+ impl < T > DoubleEndedStream for Pending < T > {
38+ fn poll_next_back ( self : Pin < & mut Self > , _: & mut Context < ' _ > ) -> Poll < Option < T > > {
39+ Poll :: Pending
40+ }
41+ }
42+
43+ impl < T > FusedStream for Pending < T > { }
44+
45+ impl < T > ExactSizeStream for Pending < T > {
46+ fn len ( & self ) -> usize {
47+ 0
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments