File tree 4 files changed +52
-0
lines changed
4 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -34,5 +34,6 @@ log = { version = "0.3", default-features = true }
34
34
scoped-tls = { version = " 0.1" , optional = true }
35
35
36
36
[features ]
37
+ never = []
37
38
use_std = [" scoped-tls" ]
38
39
default = [" use_std" ]
Original file line number Diff line number Diff line change 151
151
152
152
#![ no_std]
153
153
#![ deny( missing_docs) ]
154
+ #![ cfg_attr( feature = "never" , feature( never_type, conservative_impl_trait) ) ]
154
155
155
156
#[ macro_use]
156
157
#[ cfg( feature = "use_std" ) ]
@@ -179,11 +180,15 @@ mod empty;
179
180
mod failed;
180
181
mod finished;
181
182
mod lazy;
183
+ #[ cfg( feature = "never" ) ]
184
+ mod never;
182
185
pub use done:: { done, Done } ;
183
186
pub use empty:: { empty, Empty } ;
184
187
pub use failed:: { failed, Failed } ;
185
188
pub use finished:: { finished, Finished } ;
186
189
pub use lazy:: { lazy, Lazy } ;
190
+ #[ cfg( feature = "never" ) ]
191
+ pub use never:: { never, Never } ;
187
192
188
193
// combinators
189
194
mod and_then;
Original file line number Diff line number Diff line change
1
+ use { Future , Poll } ;
2
+
3
+ /// A future which is never resolved.
4
+ ///
5
+ /// This future can be created with the `empty` function.
6
+ pub struct Never { }
7
+
8
+ /// Creates a future which never resolves, representing a computation that never
9
+ /// finishes.
10
+ ///
11
+ /// The returned future will never resolve with a success but is still
12
+ /// susceptible to cancellation. That is, if a callback is scheduled on the
13
+ /// returned future, it is only run once the future is dropped (canceled).
14
+ pub fn never < T , E > ( ) -> impl Future < Item = T , Error = E > + Send + ' static {
15
+ ( Never { } ) . map ( |x| x) . map_err ( |x| x)
16
+ }
17
+
18
+ impl Future for Never {
19
+ type Item = !;
20
+ type Error = !;
21
+
22
+ fn poll ( & mut self ) -> Poll < !, !> {
23
+ Poll :: NotReady
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ #![ cfg_attr( feature = "never" , feature( conservative_impl_trait) ) ]
2
+
1
3
extern crate futures;
2
4
3
5
use std:: sync:: mpsc:: { channel, TryRecvError } ;
@@ -80,6 +82,25 @@ fn test_empty() {
80
82
assert_empty ( || empty ( ) . then ( |a| a) ) ;
81
83
}
82
84
85
+ #[ cfg( feature = "never" ) ]
86
+ #[ test]
87
+ fn test_never ( ) {
88
+ fn never ( ) -> impl Future < Item = i32 , Error = u32 > { futures:: never ( ) }
89
+
90
+ assert_empty ( || never ( ) ) ;
91
+ assert_empty ( || never ( ) . select ( never ( ) ) ) ;
92
+ assert_empty ( || never ( ) . join ( never ( ) ) ) ;
93
+ assert_empty ( || never ( ) . join ( f_ok ( 1 ) ) ) ;
94
+ assert_empty ( || f_ok ( 1 ) . join ( never ( ) ) ) ;
95
+ assert_empty ( || never ( ) . or_else ( move |_| never ( ) ) ) ;
96
+ assert_empty ( || never ( ) . and_then ( move |_| never ( ) ) ) ;
97
+ assert_empty ( || f_err ( 1 ) . or_else ( move |_| never ( ) ) ) ;
98
+ assert_empty ( || f_ok ( 1 ) . and_then ( move |_| never ( ) ) ) ;
99
+ assert_empty ( || never ( ) . map ( |a| a + 1 ) ) ;
100
+ assert_empty ( || never ( ) . map_err ( |a| a + 1 ) ) ;
101
+ assert_empty ( || never ( ) . then ( |a| a) ) ;
102
+ }
103
+
83
104
#[ test]
84
105
fn test_finished ( ) {
85
106
assert_done ( || finished ( 1 ) , ok ( 1 ) ) ;
You can’t perform that action at this time.
0 commit comments