You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simple function for unpackaging a core::future::Ready<T> future that has not already been polled into a T.
The contentious part is that this can panic ("Called `into_inner()` on `Ready` after completion") which is unusual for a function named .into_inner(). This design is based on the identical API in the futures crate: https://docs.rs/futures/0.3.28/futures/future/struct.Ready.html#method.into_inner. It does not return Option<T>.
I feel this was addressed convincingly enough by #101189 (comment): "in the async world I have encountered the attitude that doing anything with a Future that was already polled to completion by returning Poll::Ready will panic". The next comment by a different user reinforces that -> T is frequently used while they have never seen a case that called for -> Option<T>.
ready.into_inner() is expressible in a more roundabout way (but still zero-cost, probably) by polling once with a noop waker. (Waker::noop() tracking issue: #98286. But you can write your own noop waker today on stable with some unsafe code.)
use core::future::{self,Futureas _};use core::pin::Pin;use core::task::{Context,Poll,Waker};letmut ready = future::ready(...);let value = matchPin::new(&mut ready).poll(&mutContext::from_waker(&Waker::noop())){Poll::Ready(ready) => ready,Poll::Pending => unreachable!(),};
Be aware that a zero-cost conversion to Option<T> remains not expressible. If unwinding is enabled, one may use panic::catch_unwind(|| ready.into_inner()).ok(). Otherwise, someone with that use case will need to propose it under a different name — .take() was discussed for this in the implementation PR.
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
Thanks for the ping @m-ou-se! - I am surprised to learn this API exists. Apparently WG Async hadn't been pinged on the implementation in #101189, and it never came up in any triage issue either. Can we please file a blocking concern on WG Async having a chance to discuss this in a meeting?
I don't know whether there are any issues, but I'd like to give ourselves some time to look this over and discuss it. Thank you!
Which version is currently proposed? With all that back and forth I am confused which is current.
Ready<T>::unwrap() -> T
Ready<T>::into_inner() -> T
Ready<T>::into_inner() -> Option<T>
Currently in nightly appears to be 2. the stabilization PR currently includes changes to make it 1. and the discussion reads to me as if the current proposal is 3.
Activity
Rollup merge of rust-lang#101189 - daxpedda:ready-into-inner, r=josht…
Rollup merge of rust-lang#101189 - daxpedda:ready-into-inner, r=josht…
daxpedda commentedon Jan 10, 2023
@joshtriplett would it be acceptable to start an FCP for this? Or are there any outstanding concerns?
dtolnay commentedon Oct 10, 2023
@rust-lang/libs-api:
@rfcbot fcp merge
Simple function for unpackaging a
core::future::Ready<T>future that has not already been polled into aT.The contentious part is that this can panic ("Called `into_inner()` on `Ready` after completion") which is unusual for a function named
.into_inner(). This design is based on the identical API in thefuturescrate: https://docs.rs/futures/0.3.28/futures/future/struct.Ready.html#method.into_inner. It does not returnOption<T>.I feel this was addressed convincingly enough by #101189 (comment): "in the
asyncworld I have encountered the attitude that doing anything with aFuturethat was already polled to completion by returningPoll::Readywill panic". The next comment by a different user reinforces that-> Tis frequently used while they have never seen a case that called for-> Option<T>.ready.into_inner()is expressible in a more roundabout way (but still zero-cost, probably) by polling once with a noop waker. (Waker::noop()tracking issue: #98286. But you can write your own noop waker today on stable with some unsafe code.)Be aware that a zero-cost conversion to
Option<T>remains not expressible. If unwinding is enabled, one may usepanic::catch_unwind(|| ready.into_inner()).ok(). Otherwise, someone with that use case will need to propose it under a different name —.take()was discussed for this in the implementation PR.rfcbot commentedon Oct 10, 2023
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members:
Concerns:
async wg reviewresolved by Tracking Issue forReady::into_inner()#101196 (comment)Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
m-ou-se commentedon Nov 7, 2023
cc @rust-lang/wg-async
rfcbot commentedon Nov 7, 2023
🔔 This is now entering its final comment period, as per the review above. 🔔
yoshuawuyts commentedon Nov 7, 2023
Thanks for the ping @m-ou-se! - I am surprised to learn this API exists. Apparently WG Async hadn't been pinged on the implementation in #101189, and it never came up in any triage issue either. Can we please file a blocking concern on WG Async having a chance to discuss this in a meeting?
I don't know whether there are any issues, but I'd like to give ourselves some time to look this over and discuss it. Thank you!
BurntSushi commentedon Nov 7, 2023
@rfcbot concern async wg review
32 remaining items
BurntSushi commentedon Aug 6, 2024
@rfcbot resolve async wg review
rfcbot commentedon Aug 6, 2024
🔔 This is now entering its final comment period, as per the review above. 🔔
Skgland commentedon Aug 7, 2024
Which version is currently proposed? With all that back and forth I am confused which is current.
Ready<T>::unwrap() -> TReady<T>::into_inner() -> TReady<T>::into_inner() -> Option<T>Currently in nightly appears to be 2. the stabilization PR currently includes changes to make it 1. and the discussion reads to me as if the current proposal is 3.
dtolnay commentedon Aug 7, 2024
Number 2, I believe.
rfcbot commentedon Aug 16, 2024
The final comment period, with a disposition to merge, as per the review above, is now complete.
As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.
This will be merged soon.
Rollup merge of rust-lang#116528 - daxpedda:stabilize-ready-into-inne…
Auto merge of rust-lang#116528 - daxpedda:stabilize-ready-into-inner,…