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
14 #[allow(clippy::module_inception)]
15 mod future;
16 pub use self::future::{
17 Flatten, FlattenStream, Fuse, FutureExt, Inspect, IntoStream, Map, NeverError, Then, UnitError,
18 };
19
20 #[cfg(feature = "std")]
21 pub use self::future::CatchUnwind;
22
23 #[cfg(feature = "channel")]
24 #[cfg(feature = "std")]
25 pub use self::future::{Remote, RemoteHandle};
26
27 #[cfg(feature = "std")]
28 pub use self::future::Shared;
29
30 mod try_future;
31 pub use self::try_future::{
32 AndThen, ErrInto, InspectErr, InspectOk, IntoFuture, MapErr, MapOk, OrElse, TryFlattenStream,
33 TryFutureExt, UnwrapOrElse,
34 };
35
36 #[cfg(feature = "sink")]
37 pub use self::try_future::FlattenSink;
38
39 // Primitive futures
40
41 mod lazy;
42 pub use self::lazy::{lazy, Lazy};
43
44 mod pending;
45 pub use self::pending::{pending, Pending};
46
47 mod maybe_done;
48 pub use self::maybe_done::{maybe_done, MaybeDone};
49
50 mod option;
51 pub use self::option::OptionFuture;
52
53 mod poll_fn;
54 pub use self::poll_fn::{poll_fn, PollFn};
55
56 mod ready;
57 pub use self::ready::{err, ok, ready, Ready};
58
59 mod join;
60 pub use self::join::{join, join3, join4, join5, Join, Join3, Join4, Join5};
61
62 #[cfg(feature = "alloc")]
63 mod join_all;
64 #[cfg(feature = "alloc")]
65 pub use self::join_all::{join_all, JoinAll};
66
67 mod select;
68 pub use self::select::{select, Select};
69
70 #[cfg(feature = "alloc")]
71 mod select_all;
72 #[cfg(feature = "alloc")]
73 pub use self::select_all::{select_all, SelectAll};
74
75 mod try_join;
76 pub use self::try_join::{
77 try_join, try_join3, try_join4, try_join5, TryJoin, TryJoin3, TryJoin4, TryJoin5,
78 };
79
80 #[cfg(feature = "alloc")]
81 mod try_join_all;
82 #[cfg(feature = "alloc")]
83 pub use self::try_join_all::{try_join_all, TryJoinAll};
84
85 mod try_select;
86 pub use self::try_select::{try_select, TrySelect};
87
88 #[cfg(feature = "alloc")]
89 mod select_ok;
90 #[cfg(feature = "alloc")]
91 pub use self::select_ok::{select_ok, SelectOk};
92
93 mod either;
94 pub use self::either::Either;
95
96 cfg_target_has_atomic! {
97 #[cfg(feature = "alloc")]
98 mod abortable;
99 #[cfg(feature = "alloc")]
100 pub use self::abortable::{abortable, Abortable, AbortHandle, AbortRegistration, Aborted};
101 }
102
103 // Just a helper function to ensure the futures we're returning all have the
104 // right implementations.
assert_future<T, F>(future: F) -> F where F: Future<Output = T>,105 fn assert_future<T, F>(future: F) -> F
106 where
107 F: Future<Output = T>,
108 {
109 future
110 }
111