Skip to content

Commit 09b066c

Browse files
author
Without Boats
committed
Add minimal future APIs to support async fn.
1 parent 1533923 commit 09b066c

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

src/libcore/future.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! Futures and supporting APIs.
2+
#![unstable(feature = "async_await", issue = "50547")]
3+
4+
/// The Future trait.
5+
#[unstable(feature = "async_await", issue = "50547")]
6+
pub trait Future { }

src/libcore/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,11 @@ pub mod ascii;
191191
pub mod sync;
192192
pub mod cell;
193193
pub mod char;
194-
pub mod panic;
195-
pub mod panicking;
194+
pub mod future;
196195
pub mod iter;
197196
pub mod option;
197+
pub mod panic;
198+
pub mod panicking;
198199
pub mod raw;
199200
pub mod result;
200201

src/libcore/raw.rs

+27
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,30 @@ pub struct TraitObject {
9797
pub data: *mut (),
9898
pub vtable: *mut (),
9999
}
100+
101+
/// An adapter from a generator to a future.
102+
///
103+
/// This is a permanently unstable API used by the compiler. You should not
104+
/// depend on it.
105+
#[allow(missing_debug_implementations, dead_code)]
106+
#[unstable(feature = "gen_future", issue = "50547")]
107+
pub struct GenFuture<G, R> {
108+
gen: G,
109+
marker: ::marker::PhantomData<R>,
110+
}
111+
112+
/// Construct a future from a generator (used in lowering async functions).
113+
///
114+
/// This is a permanently unstable API used by the compiler. You should not
115+
/// depend on it.
116+
#[unstable(feature = "gen_future", issue = "50547")]
117+
pub fn gen_future<G>(gen: G) -> GenFuture<G, G::Return> where
118+
G: ::ops::Generator<Yield = ()>
119+
{
120+
GenFuture { gen, marker: ::marker::PhantomData }
121+
}
122+
123+
#[unstable(feature = "gen_future", issue = "50547")]
124+
impl<G> ::future::Future for GenFuture<G, G::Return> where
125+
G: ::ops::Generator<Yield = ()>
126+
{ }

src/libstd/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
#![feature(array_error_internals)]
243243
#![feature(ascii_ctype)]
244244
#![feature(asm)]
245+
#![feature(async_await)]
245246
#![feature(attr_literals)]
246247
#![feature(box_syntax)]
247248
#![feature(cfg_target_has_atomic)]
@@ -390,6 +391,8 @@ pub use core::cmp;
390391
pub use core::convert;
391392
#[stable(feature = "rust1", since = "1.0.0")]
392393
pub use core::default;
394+
#[unstable(feature = "async_await", issue = "50547")]
395+
pub use core::future;
393396
#[stable(feature = "rust1", since = "1.0.0")]
394397
pub use core::hash;
395398
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)