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