Skip to content

Commit 141ce5f

Browse files
authored
Rollup merge of rust-lang#72459 - yoshuawuyts:into-future, r=nikomatsakis
Add core::future::IntoFuture This patch reintroduces the `core::future::IntoFuture` trait. However unlike earlier PRs this patch does not integrate it into the `async/.await` lowering since that lead to performance regressions. By introducing the trait separately from the integration, the integration PR can be more narrowly scoped, and people can start trying out the `IntoFuture` trait today. Thanks heaps! cc/ @rust-lang/wg-async-foundations ## References - Original PR adding `IntoFuture` rust-lang#65244 - Open issue to re-land `IntoFuture` (assigned to me) rust-lang#67982 - Tracking issue for `IntoFuture` rust-lang#67644
2 parents 3083ce7 + 9ff5020 commit 141ce5f

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

src/libcore/future/into_future.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use crate::future::Future;
2+
3+
/// Conversion into a `Future`.
4+
#[unstable(feature = "into_future", issue = "67644")]
5+
pub trait IntoFuture {
6+
/// The output that the future will produce on completion.
7+
#[unstable(feature = "into_future", issue = "67644")]
8+
type Output;
9+
10+
/// Which kind of future are we turning this into?
11+
#[unstable(feature = "into_future", issue = "67644")]
12+
type Future: Future<Output = Self::Output>;
13+
14+
/// Creates a future from a value.
15+
#[unstable(feature = "into_future", issue = "67644")]
16+
fn into_future(self) -> Self::Future;
17+
}
18+
19+
#[unstable(feature = "into_future", issue = "67644")]
20+
impl<F: Future> IntoFuture for F {
21+
type Output = F::Output;
22+
type Future = F;
23+
24+
fn into_future(self) -> Self::Future {
25+
self
26+
}
27+
}

src/libcore/future/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ use crate::{
1010
};
1111

1212
mod future;
13+
mod into_future;
1314
mod pending;
1415
mod ready;
1516

1617
#[stable(feature = "futures_api", since = "1.36.0")]
1718
pub use self::future::Future;
1819

20+
#[unstable(feature = "into_future", issue = "67644")]
21+
pub use into_future::IntoFuture;
22+
1923
#[unstable(feature = "future_readiness_fns", issue = "70921")]
2024
pub use pending::{pending, Pending};
2125
#[unstable(feature = "future_readiness_fns", issue = "70921")]

src/libstd/future.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,16 @@
22
33
#[doc(inline)]
44
#[stable(feature = "futures_api", since = "1.36.0")]
5-
pub use core::future::*;
5+
pub use core::future::Future;
6+
7+
#[doc(inline)]
8+
#[unstable(feature = "gen_future", issue = "50547")]
9+
pub use core::future::{from_generator, get_context, ResumeTy};
10+
11+
#[doc(inline)]
12+
#[unstable(feature = "future_readiness_fns", issue = "70921")]
13+
pub use core::future::{pending, ready, Pending, Ready};
14+
15+
#[doc(inline)]
16+
#[unstable(feature = "into_future", issue = "67644")]
17+
pub use core::future::IntoFuture;

src/libstd/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,15 @@
266266
#![feature(external_doc)]
267267
#![feature(fn_traits)]
268268
#![feature(format_args_nl)]
269+
#![feature(future_readiness_fns)]
270+
#![feature(gen_future)]
269271
#![feature(generator_trait)]
270272
#![feature(global_asm)]
271273
#![feature(hash_raw_entry)]
272274
#![feature(hashmap_internals)]
273275
#![feature(int_error_internals)]
274276
#![feature(int_error_matching)]
277+
#![feature(into_future)]
275278
#![feature(integer_atomics)]
276279
#![feature(lang_items)]
277280
#![feature(libc)]

0 commit comments

Comments
 (0)