diff options
| author | Sean McArthur <sean@seanmonstar.com> | 2019-12-26 12:57:09 -0800 |
|---|---|---|
| committer | Sean McArthur <sean@seanmonstar.com> | 2019-12-27 11:56:11 -0800 |
| commit | f35517ee861dc012ccc26083dd4520045e2c4f6f (patch) | |
| tree | 7a45f4f0a3eee9c1e3173d7f85162edda8a80543 /src/libcore/future | |
| parent | 41501a6b03a8f10d8c29dfcb37dbd5ff84b33f34 (diff) | |
| download | rust-f35517ee861dc012ccc26083dd4520045e2c4f6f.tar.gz rust-f35517ee861dc012ccc26083dd4520045e2c4f6f.zip | |
core: add IntoFuture trait and support for await
Diffstat (limited to 'src/libcore/future')
| -rw-r--r-- | src/libcore/future/future.rs | 25 | ||||
| -rw-r--r-- | src/libcore/future/mod.rs | 3 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/libcore/future/future.rs b/src/libcore/future/future.rs index f14ed38b9b0..dcb819f9381 100644 --- a/src/libcore/future/future.rs +++ b/src/libcore/future/future.rs @@ -99,6 +99,21 @@ pub trait Future { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>; } +/// 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; +} + #[stable(feature = "futures_api", since = "1.36.0")] impl<F: ?Sized + Future + Unpin> Future for &mut F { type Output = F::Output; @@ -119,3 +134,13 @@ where Pin::get_mut(self).as_mut().poll(cx) } } + +#[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 89ea4713cfd..aecd57b9ce7 100644 --- a/src/libcore/future/mod.rs +++ b/src/libcore/future/mod.rs @@ -5,3 +5,6 @@ mod future; #[stable(feature = "futures_api", since = "1.36.0")] pub use self::future::Future; + +#[unstable(feature = "into_future", issue = "67644")] +pub use self::future::IntoFuture; |
