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