diff options
| author | Yoshua Wuyts <yoshuawuyts@gmail.com> | 2020-05-22 10:07:46 +0200 |
|---|---|---|
| committer | Yoshua Wuyts <yoshuawuyts@gmail.com> | 2020-05-22 10:55:01 +0200 |
| commit | 9ff502029d379bebc50cf92a97f019fefba09d79 (patch) | |
| tree | 52ee5155f7e2c6d9d2a6f4499f07bd5c6be09e03 | |
| parent | 458a3e76294fd859fb037f425404180c91e14767 (diff) | |
| download | rust-9ff502029d379bebc50cf92a97f019fefba09d79.tar.gz rust-9ff502029d379bebc50cf92a97f019fefba09d79.zip | |
Add core::future::IntoFuture
This patch adds `core::future::IntoFuture`. However unlike earlier PRs this patch does not integrate it into the `async/.await` lowering. That integration should be done in a follow-up PR.
| -rw-r--r-- | src/libcore/future/into_future.rs | 27 | ||||
| -rw-r--r-- | src/libcore/future/mod.rs | 4 | ||||
| -rw-r--r-- | src/libstd/future.rs | 14 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 3 |
4 files changed, 47 insertions, 1 deletions
diff --git a/src/libcore/future/into_future.rs b/src/libcore/future/into_future.rs new file mode 100644 index 00000000000..4020c254446 --- /dev/null +++ b/src/libcore/future/into_future.rs @@ -0,0 +1,27 @@ +use crate::future::Future; + +/// Conversion into a `Future`. +#[unstable(feature = "into_future", issue = "67644")] +pub trait IntoFuture { + /// The output that the future will produce on completion. + #[unstable(feature = "into_future", issue = "67644")] + type Output; + + /// Which kind of future are we turning this into? + #[unstable(feature = "into_future", issue = "67644")] + type Future: Future<Output = Self::Output>; + + /// Creates a future from a value. + #[unstable(feature = "into_future", issue = "67644")] + fn into_future(self) -> Self::Future; +} + +#[unstable(feature = "into_future", issue = "67644")] +impl<F: Future> IntoFuture for F { + type Output = F::Output; + type Future = F; + + fn into_future(self) -> Self::Future { + self + } +} diff --git a/src/libcore/future/mod.rs b/src/libcore/future/mod.rs index b5a102916a0..6f6009b47e6 100644 --- a/src/libcore/future/mod.rs +++ b/src/libcore/future/mod.rs @@ -10,12 +10,16 @@ use crate::{ }; mod future; +mod into_future; mod pending; mod ready; #[stable(feature = "futures_api", since = "1.36.0")] pub use self::future::Future; +#[unstable(feature = "into_future", issue = "67644")] +pub use into_future::IntoFuture; + #[unstable(feature = "future_readiness_fns", issue = "70921")] pub use pending::{pending, Pending}; #[unstable(feature = "future_readiness_fns", issue = "70921")] diff --git a/src/libstd/future.rs b/src/libstd/future.rs index e2092cfefa3..89dd9fb9b2c 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -2,4 +2,16 @@ #[doc(inline)] #[stable(feature = "futures_api", since = "1.36.0")] -pub use core::future::*; +pub use core::future::Future; + +#[doc(inline)] +#[unstable(feature = "gen_future", issue = "50547")] +pub use core::future::{from_generator, get_context, ResumeTy}; + +#[doc(inline)] +#[unstable(feature = "future_readiness_fns", issue = "70921")] +pub use core::future::{pending, ready, Pending, Ready}; + +#[doc(inline)] +#[unstable(feature = "into_future", issue = "67644")] +pub use core::future::IntoFuture; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index ac07af5e278..cc3e613fa3d 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -266,12 +266,15 @@ #![feature(external_doc)] #![feature(fn_traits)] #![feature(format_args_nl)] +#![feature(future_readiness_fns)] +#![feature(gen_future)] #![feature(generator_trait)] #![feature(global_asm)] #![feature(hash_raw_entry)] #![feature(hashmap_internals)] #![feature(int_error_internals)] #![feature(int_error_matching)] +#![feature(into_future)] #![feature(integer_atomics)] #![feature(lang_items)] #![feature(libc)] |
