Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add core::future::IntoFuture #72459

Merged
merged 1 commit into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/libcore/future/into_future.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
4 changes: 4 additions & 0 deletions src/libcore/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
14 changes: 13 additions & 1 deletion src/libstd/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 3 additions & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down