File tree 6 files changed +62
-0
lines changed
6 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ io-compat = ["compat", "tokio-io"]
22
22
bench = []
23
23
nightly = [" futures-core-preview/nightly" , " futures-sink-preview/nightly" ]
24
24
cfg-target-has-atomic = [" futures-core-preview/cfg-target-has-atomic" ]
25
+ never-type = []
25
26
alloc = [" futures-core-preview/alloc" , " futures-sink-preview/alloc" ]
26
27
27
28
[dependencies ]
Original file line number Diff line number Diff line change @@ -70,6 +70,11 @@ pub use self::inspect::Inspect;
70
70
mod unit_error;
71
71
pub use self :: unit_error:: UnitError ;
72
72
73
+ #[ cfg( feature = "never-type" ) ]
74
+ mod never_error;
75
+ #[ cfg( feature = "never-type" ) ]
76
+ pub use self :: never_error:: NeverError ;
77
+
73
78
// Implementation details
74
79
mod chain;
75
80
pub ( crate ) use self :: chain:: Chain ;
@@ -537,6 +542,15 @@ pub trait FutureExt: Future {
537
542
UnitError :: new ( self )
538
543
}
539
544
545
+ #[ cfg( feature = "never-type" ) ]
546
+ /// Turns a [`Future<Output = T>`](Future) into a
547
+ /// [`TryFuture<Ok = T, Error = !`>](futures_core::future::TryFuture).
548
+ fn never_error ( self ) -> NeverError < Self >
549
+ where Self : Sized
550
+ {
551
+ NeverError :: new ( self )
552
+ }
553
+
540
554
/// A convenience for calling `Future::poll` on `Unpin` future types.
541
555
fn poll_unpin ( & mut self , cx : & mut Context < ' _ > ) -> Poll < Self :: Output >
542
556
where Self : Unpin + Sized
Original file line number Diff line number Diff line change
1
+ use core:: pin:: Pin ;
2
+ use futures_core:: future:: { FusedFuture , Future } ;
3
+ use futures_core:: task:: { self , Poll } ;
4
+ use pin_utils:: unsafe_pinned;
5
+
6
+ /// Future for the [`never_error`](super::FutureExt::never_error) combinator.
7
+ #[ derive( Debug ) ]
8
+ #[ must_use = "futures do nothing unless polled" ]
9
+ pub struct NeverError < Fut > {
10
+ future : Fut ,
11
+ }
12
+
13
+ impl < Fut > NeverError < Fut > {
14
+ unsafe_pinned ! ( future: Fut ) ;
15
+
16
+ pub ( super ) fn new ( future : Fut ) -> NeverError < Fut > {
17
+ NeverError { future }
18
+ }
19
+ }
20
+
21
+ impl < Fut : Unpin > Unpin for NeverError < Fut > { }
22
+
23
+ impl < Fut : FusedFuture > FusedFuture for NeverError < Fut > {
24
+ fn is_terminated ( & self ) -> bool { self . future . is_terminated ( ) }
25
+ }
26
+
27
+ impl < Fut , T > Future for NeverError < Fut >
28
+ where Fut : Future < Output = T > ,
29
+ {
30
+ type Output = Result < T , !> ;
31
+
32
+ fn poll ( self : Pin < & mut Self > , cx : & mut task:: Context < ' _ > ) -> Poll < Result < T , !> > {
33
+ self . future ( ) . poll ( cx) . map ( Ok )
34
+ }
35
+ }
Original file line number Diff line number Diff line change 5
5
#![ cfg_attr( feature = "alloc" , feature( box_into_pin) ) ]
6
6
#![ cfg_attr( feature = "std" , feature( async_await, await_macro) ) ]
7
7
#![ cfg_attr( feature = "cfg-target-has-atomic" , feature( cfg_target_has_atomic) ) ]
8
+ #![ cfg_attr( feature = "never-type" , feature( never_type) ) ]
8
9
9
10
#![ cfg_attr( not( feature = "std" ) , no_std) ]
10
11
#![ warn( missing_docs, missing_debug_implementations, rust_2018_idioms) ]
14
15
#[ cfg( all( feature = "cfg-target-has-atomic" , not( feature = "nightly" ) ) ) ]
15
16
compile_error ! ( "The `cfg-target-has-atomic` feature requires the `nightly` feature as an explicit opt-in to unstable features" ) ;
16
17
18
+ #[ cfg( all( feature = "never-type" , not( feature = "nightly" ) ) ) ]
19
+ compile_error ! ( "The `never-type` feature requires the `nightly` feature as an explicit opt-in to unstable features" ) ;
20
+
17
21
#[ cfg( feature = "alloc" ) ]
18
22
extern crate alloc;
19
23
Original file line number Diff line number Diff line change @@ -42,4 +42,5 @@ default = ["std"]
42
42
compat = [" std" , " futures-util-preview/compat" ]
43
43
io-compat = [" compat" , " futures-util-preview/io-compat" ]
44
44
cfg-target-has-atomic = [" futures-core-preview/cfg-target-has-atomic" , " futures-util-preview/cfg-target-has-atomic" ]
45
+ never-type = [" futures-util-preview/never-type" ]
45
46
alloc = [" futures-core-preview/alloc" , " futures-sink-preview/alloc" , " futures-util-preview/alloc" ]
Original file line number Diff line number Diff line change 23
23
24
24
#![ feature( futures_api) ]
25
25
#![ cfg_attr( feature = "cfg-target-has-atomic" , feature( cfg_target_has_atomic) ) ]
26
+ #![ cfg_attr( feature = "never-type" , feature( never_type) ) ]
26
27
27
28
#![ cfg_attr( not( feature = "std" ) , no_std) ]
28
29
33
34
#[ cfg( all( feature = "cfg-target-has-atomic" , not( feature = "nightly" ) ) ) ]
34
35
compile_error ! ( "The `cfg-target-has-atomic` feature requires the `nightly` feature as an explicit opt-in to unstable features" ) ;
35
36
37
+ #[ cfg( all( feature = "never-type" , not( feature = "nightly" ) ) ) ]
38
+ compile_error ! ( "The `never-type` feature requires the `nightly` feature as an explicit opt-in to unstable features" ) ;
39
+
36
40
#[ doc( hidden) ] pub use futures_util:: core_reexport;
37
41
38
42
#[ doc( hidden) ] pub use futures_core:: future:: Future ;
@@ -230,6 +234,9 @@ pub mod future {
230
234
UnwrapOrElse ,
231
235
} ;
232
236
237
+ #[ cfg( feature = "never-type" ) ]
238
+ pub use futures_util:: future:: NeverError ;
239
+
233
240
#[ cfg( feature = "alloc" ) ]
234
241
pub use futures_util:: try_future:: {
235
242
try_join_all, TryJoinAll ,
You can’t perform that action at this time.
0 commit comments