about summary refs log tree commit diff
path: root/src/libcore/future/mod.rs
AgeCommit message (Collapse)AuthorLines
2020-07-27mv std libs to library/mark-95/+0
2020-07-10Rollup merge of #72303 - yoshuawuyts:future-poll-fn, r=dtolnayManish Goregaokar-0/+4
Add core::future::{poll_fn, PollFn} This is a sibling PR to #70834, adding `future::poll_fn`. This is a small helper function that helps bridge the gap between "poll state machines" and "async/await". It was first introduced in [futures@0.1.7](https://docs.rs/futures/0.1.7/futures/future/fn.poll_fn.html) in December of 2016, and has been tried and tested as part of the ecosystem for the past 3.5 years. ## Implementation Much of the same reasoning from #70834 applies: by returning a concrete struct rather than an `async fn` we get to mark the future as `Unpin`. It also becomes named which allows storing it in structs without boxing. This implementation has been modified from the implementation in `futures-rs`. ## References - [`futures::future::poll_fn`](https://docs.rs/futures/0.3.5/futures/future/fn.poll_fn.html) - [`async_std::future::poll_fn`](https://docs.rs/async-std/1.5.0/async_std/future/fn.poll_fn.html)
2020-06-30Deny unsafe ops in unsafe fns, part 6LeSeulArtichaut-1/+3
And final part!!!
2020-05-25Display information about captured variable in `FnMut` errorAaron Hill-0/+1
Fixes #69446 When we encounter a region error involving an `FnMut` closure, we display a specialized error message. However, we currently do not tell the user which upvar was captured. This makes it difficult to determine the cause of the error, especially when the closure is large. This commit records marks constraints involving closure upvars with `ConstraintCategory::ClosureUpvar`. When we decide to 'blame' a `ConstraintCategory::Return`, we additionall store the captured upvar if we found a `ConstraintCategory::ClosureUpvar` in the path. When generating an error message, we point to relevant spans if we have closure upvar information available. We further customize the message if an `async` closure is being returned, to make it clear that the captured variable is being returned indirectly.
2020-05-22Add core::future::IntoFutureYoshua Wuyts-0/+4
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.
2020-05-18Add core::future::{poll_fn, PollFn}Yoshua Wuyts-0/+4
2020-05-09Rollup merge of #70834 - yoshuawuyts:future-pending-ready, r=sfacklerDylan DPC-0/+8
Add core::future::{pending,ready} Adds two future constructors to `core`: `future::ready` and `future::pending`. These functions enable constructing futures of any type that either immediately resolve, or never resolve which is an incredible useful tool when writing documentation. These functions have prior art in both the `futures` and `async-std` crates. This implementation has been adapted from the `futures` crate. ## Examples In https://github.com/rust-lang/rust/pull/70817 we propose adding the `ready!` macro. In the example we use an `async fn` which does not return a future that implements `Unpin`, which leads to the use of `unsafe`. Instead had we had `future::ready` available, we could've written the same example without using `unsafe`: ```rust use core::task::{Context, Poll}; use core::future::{self, Future}; use core::pin::Pin; pub fn do_poll(cx: &mut Context<'_>) -> Poll<()> { let mut fut = future::ready(42_u8); let num = ready!(Pin::new(fut).poll(cx)); // ... use num Poll::Ready(()) } ``` ## Why future::ready? Arguably `future::ready` and `async {}` can be considered equivalent. The main differences are that `future::ready` returns a future that implements `Unpin`, and the returned future is a concrete type. This is useful for traits that require a future as an associated type that can sometimes be a no-op ([example](https://docs.rs/http-service/0.4.0/http_service/trait.HttpService.html#associatedtype.ConnectionFuture)). The final, minor argument is that `future::ready` and `future::pending` form a counterpart to the enum members of `Poll`: `Ready` and `Pending`. These functions form a conceptual bridge between `Poll` and `Future`, and can be used as a useful teaching device. ## References - [`futures::future::ready`](https://docs.rs/futures/0.3.4/futures/future/fn.ready.html) - [`futures::future::pending`](https://docs.rs/futures/0.3.4/futures/future/fn.pending.html) - [`async_std::future::pending`](https://docs.rs/async-std/1.5.0/async_std/future/fn.pending.html) - [`async_std::future::ready`](https://docs.rs/async-std/1.5.0/async_std/future/fn.ready.html)
2020-05-07Add core::future::{pending,ready}Yoshua Wuyts-0/+8
2020-04-25Bump bootstrap compilerMark Rousskov-6/+0
2020-04-05Remove a stack frame from .await callsSteven Fackler-5/+2
2020-03-17Add issue referenceJonas Schievink-1/+1
2020-03-17Clarify commentJonas Schievink-1/+1
2020-03-17Make `ResumeTy` contents privateJonas Schievink-1/+1
2020-03-17Remove useless derives on `GenFuture`Jonas Schievink-1/+0
Not sure why these were there, I guess because this type used to kind of be part of public API?
2020-03-17FormatJonas Schievink-1/+1
2020-03-17Add futures scaffolding to libcoreJonas Schievink-0/+79
2019-12-31Revert "core: add IntoFuture trait and support for await"Wesley Wiser-3/+0
This reverts commit f35517ee861dc012ccc26083dd4520045e2c4f6f.
2019-12-27core: add IntoFuture trait and support for awaitSean McArthur-0/+3
2019-04-23Stabilize futures_apiTaylor Cramer-3/+2
2018-12-25Remove licensesMark Rousskov-10/+0
2018-09-19Remove spawning from task::ContextTaylor Cramer-3/+0
2018-07-02Add lifetime to `FutureObj`Josef Reinhard Brandl-0/+21