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.
This commit is contained in:
parent
458a3e7629
commit
9ff502029d
4 changed files with 47 additions and 1 deletions
27
src/libcore/future/into_future.rs
Normal file
27
src/libcore/future/into_future.rs
Normal file
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,12 +10,16 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
mod future;
|
mod future;
|
||||||
|
mod into_future;
|
||||||
mod pending;
|
mod pending;
|
||||||
mod ready;
|
mod ready;
|
||||||
|
|
||||||
#[stable(feature = "futures_api", since = "1.36.0")]
|
#[stable(feature = "futures_api", since = "1.36.0")]
|
||||||
pub use self::future::Future;
|
pub use self::future::Future;
|
||||||
|
|
||||||
|
#[unstable(feature = "into_future", issue = "67644")]
|
||||||
|
pub use into_future::IntoFuture;
|
||||||
|
|
||||||
#[unstable(feature = "future_readiness_fns", issue = "70921")]
|
#[unstable(feature = "future_readiness_fns", issue = "70921")]
|
||||||
pub use pending::{pending, Pending};
|
pub use pending::{pending, Pending};
|
||||||
#[unstable(feature = "future_readiness_fns", issue = "70921")]
|
#[unstable(feature = "future_readiness_fns", issue = "70921")]
|
||||||
|
|
|
@ -2,4 +2,16 @@
|
||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
#[stable(feature = "futures_api", since = "1.36.0")]
|
#[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;
|
||||||
|
|
|
@ -266,12 +266,15 @@
|
||||||
#![feature(external_doc)]
|
#![feature(external_doc)]
|
||||||
#![feature(fn_traits)]
|
#![feature(fn_traits)]
|
||||||
#![feature(format_args_nl)]
|
#![feature(format_args_nl)]
|
||||||
|
#![feature(future_readiness_fns)]
|
||||||
|
#![feature(gen_future)]
|
||||||
#![feature(generator_trait)]
|
#![feature(generator_trait)]
|
||||||
#![feature(global_asm)]
|
#![feature(global_asm)]
|
||||||
#![feature(hash_raw_entry)]
|
#![feature(hash_raw_entry)]
|
||||||
#![feature(hashmap_internals)]
|
#![feature(hashmap_internals)]
|
||||||
#![feature(int_error_internals)]
|
#![feature(int_error_internals)]
|
||||||
#![feature(int_error_matching)]
|
#![feature(int_error_matching)]
|
||||||
|
#![feature(into_future)]
|
||||||
#![feature(integer_atomics)]
|
#![feature(integer_atomics)]
|
||||||
#![feature(lang_items)]
|
#![feature(lang_items)]
|
||||||
#![feature(libc)]
|
#![feature(libc)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue