From 9ff502029d379bebc50cf92a97f019fefba09d79 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Fri, 22 May 2020 10:07:46 +0200 Subject: 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. --- src/libcore/future/into_future.rs | 27 +++++++++++++++++++++++++++ src/libcore/future/mod.rs | 4 ++++ 2 files changed, 31 insertions(+) create mode 100644 src/libcore/future/into_future.rs (limited to 'src/libcore') 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; + + /// 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 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")] -- cgit 1.4.1-3-g733a5