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 @@ -18,4 +18,5 @@ log = { version = "0.3", default-features = false }
18
18
19
19
[features ]
20
20
use_std = []
21
+ never = []
21
22
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" ) ]
@@ -176,11 +177,15 @@ mod empty;
176
177
mod failed;
177
178
mod finished;
178
179
mod lazy;
180
+ #[ cfg( feature = "never" ) ]
181
+ mod never;
179
182
pub use done:: { done, Done } ;
180
183
pub use empty:: { empty, Empty } ;
181
184
pub use failed:: { failed, Failed } ;
182
185
pub use finished:: { finished, Finished } ;
183
186
pub use lazy:: { lazy, Lazy } ;
187
+ #[ cfg( feature = "never" ) ]
188
+ pub use never:: { never, Never } ;
184
189
185
190
// combinators
186
191
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 } ;
@@ -79,6 +81,25 @@ fn test_empty() {
79
81
assert_empty ( || empty ( ) . then ( |a| a) ) ;
80
82
}
81
83
84
+ #[ cfg( feature = "never" ) ]
85
+ #[ test]
86
+ fn test_never ( ) {
87
+ fn never ( ) -> impl Future < Item = i32 , Error = u32 > { futures:: never ( ) }
88
+
89
+ assert_empty ( || never ( ) ) ;
90
+ assert_empty ( || never ( ) . select ( never ( ) ) ) ;
91
+ assert_empty ( || never ( ) . join ( never ( ) ) ) ;
92
+ assert_empty ( || never ( ) . join ( f_ok ( 1 ) ) ) ;
93
+ assert_empty ( || f_ok ( 1 ) . join ( never ( ) ) ) ;
94
+ assert_empty ( || never ( ) . or_else ( move |_| never ( ) ) ) ;
95
+ assert_empty ( || never ( ) . and_then ( move |_| never ( ) ) ) ;
96
+ assert_empty ( || f_err ( 1 ) . or_else ( move |_| never ( ) ) ) ;
97
+ assert_empty ( || f_ok ( 1 ) . and_then ( move |_| never ( ) ) ) ;
98
+ assert_empty ( || never ( ) . map ( |a| a + 1 ) ) ;
99
+ assert_empty ( || never ( ) . map_err ( |a| a + 1 ) ) ;
100
+ assert_empty ( || never ( ) . then ( |a| a) ) ;
101
+ }
102
+
82
103
#[ test]
83
104
fn test_finished ( ) {
84
105
assert_done ( || finished ( 1 ) , ok ( 1 ) ) ;
You can’t perform that action at this time.
0 commit comments