1 //! Futures
2 //!
3 //! This module contains a number of functions for working with `Future`s,
4 //! including the [`FutureExt`] trait and the [`TryFutureExt`] trait which add
5 //! methods to `Future` types.
6 
7 #[cfg(feature = "alloc")]
8 pub use futures_core::future::{BoxFuture, LocalBoxFuture};
9 pub use futures_core::future::{FusedFuture, Future, TryFuture};
10 pub use futures_task::{FutureObj, LocalFutureObj, UnsafeFutureObj};
11 
12 // Extension traits and combinators
13 #[allow(clippy::module_inception)]
14 mod future;
15 pub use self::future::{
16     Flatten, Fuse, FutureExt, Inspect, IntoStream, Map, NeverError, Then, UnitError, MapInto,
17 };
18 
19 #[deprecated(note = "This is now an alias for [Flatten](Flatten)")]
20 pub use self::future::FlattenStream;
21 
22 #[cfg(feature = "std")]
23 pub use self::future::CatchUnwind;
24 
25 #[cfg(feature = "channel")]
26 #[cfg(feature = "std")]
27 pub use self::future::{Remote, RemoteHandle};
28 
29 #[cfg(feature = "std")]
30 pub use self::future::Shared;
31 
32 mod try_future;
33 pub use self::try_future::{
34     AndThen, ErrInto, OkInto, InspectErr, InspectOk, IntoFuture, MapErr, MapOk, OrElse, TryFlattenStream,
35     TryFutureExt, UnwrapOrElse, MapOkOrElse, TryFlatten,
36 };
37 
38 #[cfg(feature = "sink")]
39 pub use self::try_future::FlattenSink;
40 
41 // Primitive futures
42 
43 mod lazy;
44 pub use self::lazy::{lazy, Lazy};
45 
46 mod pending;
47 pub use self::pending::{pending, Pending};
48 
49 mod maybe_done;
50 pub use self::maybe_done::{maybe_done, MaybeDone};
51 
52 mod try_maybe_done;
53 pub use self::try_maybe_done::{try_maybe_done, TryMaybeDone};
54 
55 mod option;
56 pub use self::option::OptionFuture;
57 
58 mod poll_fn;
59 pub use self::poll_fn::{poll_fn, PollFn};
60 
61 mod ready;
62 pub use self::ready::{err, ok, ready, Ready};
63 
64 mod join;
65 pub use self::join::{join, join3, join4, join5, Join, Join3, Join4, Join5};
66 
67 #[cfg(feature = "alloc")]
68 mod join_all;
69 #[cfg(feature = "alloc")]
70 pub use self::join_all::{join_all, JoinAll};
71 
72 mod select;
73 pub use self::select::{select, Select};
74 
75 #[cfg(feature = "alloc")]
76 mod select_all;
77 #[cfg(feature = "alloc")]
78 pub use self::select_all::{select_all, SelectAll};
79 
80 mod try_join;
81 pub use self::try_join::{
82     try_join, try_join3, try_join4, try_join5, TryJoin, TryJoin3, TryJoin4, TryJoin5,
83 };
84 
85 #[cfg(feature = "alloc")]
86 mod try_join_all;
87 #[cfg(feature = "alloc")]
88 pub use self::try_join_all::{try_join_all, TryJoinAll};
89 
90 mod try_select;
91 pub use self::try_select::{try_select, TrySelect};
92 
93 #[cfg(feature = "alloc")]
94 mod select_ok;
95 #[cfg(feature = "alloc")]
96 pub use self::select_ok::{select_ok, SelectOk};
97 
98 mod either;
99 pub use self::either::Either;
100 
101 cfg_target_has_atomic! {
102     #[cfg(feature = "alloc")]
103     mod abortable;
104     #[cfg(feature = "alloc")]
105     pub use self::abortable::{abortable, Abortable, AbortHandle, AbortRegistration, Aborted};
106 }
107 
108 // Just a helper function to ensure the futures we're returning all have the
109 // right implementations.
assert_future<T, F>(future: F) -> F where F: Future<Output = T>,110 fn assert_future<T, F>(future: F) -> F
111 where
112     F: Future<Output = T>,
113 {
114     future
115 }
116