1
+ #[ cfg( not( feature = "nightly" ) ) ]
1
2
use std:: marker;
2
3
3
4
use { Future , Task , Poll } ;
4
5
5
6
/// A future which is never resolved.
6
7
///
7
8
/// This future can be created with the `empty` function.
9
+ #[ cfg( feature = "nightly" ) ]
10
+ pub struct Never { }
11
+
12
+ /// A future which is never resolved.
13
+ ///
14
+ /// This future can be created with the `empty` function.
15
+ #[ cfg( not( feature = "nightly" ) ) ]
8
16
pub struct Never < T , E >
9
17
where T : ' static ,
10
18
E : ' static ,
@@ -18,10 +26,39 @@ pub struct Never<T, E>
18
26
/// The returned future will never resolve with a success but is still
19
27
/// susceptible to cancellation. That is, if a callback is scheduled on the
20
28
/// returned future, it is only run once the future is dropped (canceled).
29
+ #[ cfg( feature = "nightly" ) ]
30
+ pub fn never < T , E > ( ) -> impl Future < Item = T , Error = E > + Send + ' static
31
+ where T : ' static ,
32
+ E : ' static ,
33
+ {
34
+ ( Never { } )
35
+ . map ( |x| x)
36
+ . map_err ( |x| x)
37
+ }
38
+
39
+ /// Creates a future which never resolves, representing a computation that never
40
+ /// finishes.
41
+ ///
42
+ /// The returned future will never resolve with a success but is still
43
+ /// susceptible to cancellation. That is, if a callback is scheduled on the
44
+ /// returned future, it is only run once the future is dropped (canceled).
45
+ #[ cfg( not( feature = "nightly" ) ) ]
21
46
pub fn never < T : ' static , E : ' static > ( ) -> Never < T , E > {
22
47
Never { _data : marker:: PhantomData }
23
48
}
24
49
50
+ #[ cfg( feature = "nightly" ) ]
51
+ impl Future for Never {
52
+ type Item = !;
53
+ type Error = !;
54
+
55
+ fn poll ( & mut self , _: & mut Task ) -> Poll < !, !> {
56
+ Poll :: NotReady
57
+ }
58
+
59
+ fn schedule ( & mut self , _task : & mut Task ) { }
60
+ }
61
+ #[ cfg( not( feature = "nightly" ) ) ]
25
62
impl < T , E > Future for Never < T , E >
26
63
where T : ' static ,
27
64
E : ' static ,
0 commit comments