diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2020-07-18 16:50:50 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-18 16:50:50 -0700 |
| commit | 479c8ad17c6908bd792dcacb0a3e0b5503903cf4 (patch) | |
| tree | 1b3a4b37d184000e04ca9da8b2d9d65cd91bf688 /library/std/src/sys/unix/stack_overflow.rs | |
| parent | 1fa54ad9680cc82e7301f8ed4e9b7402dfd6ce0e (diff) | |
| parent | 18be370342c9b2a93f1d56b2b674bd2fbdcbb019 (diff) | |
| download | rust-479c8ad17c6908bd792dcacb0a3e0b5503903cf4.tar.gz rust-479c8ad17c6908bd792dcacb0a3e0b5503903cf4.zip | |
Rollup merge of #70817 - yoshuawuyts:task-ready, r=dtolnay
Add core::task::ready! macro
This PR adds `ready!` as a top-level macro to `libcore` following the implementation of `futures_core::ready`, tracking issue https://github.com/rust-lang/rust/issues/70922. This macro is commonly used when implementing `Future`, `AsyncRead`, `AsyncWrite` and `Stream`. And being only 5 lines, it seems like a useful and straight forward addition to std.
## Example
```rust
use core::task::{Context, Poll};
use core::future::Future;
use core::pin::Pin;
async fn get_num() -> usize {
42
}
pub fn do_poll(cx: &mut Context<'_>) -> Poll<()> {
let mut f = get_num();
let f = unsafe { Pin::new_unchecked(&mut f) };
let num = ready!(f.poll(cx));
// ... use num
Poll::Ready(())
}
```
## Naming
In `async-std` we chose to nest the macro under the `task` module instead of having the macro at the top-level. This is a pattern that currently does not occur in std, mostly due to this not being possible prior to Rust 2018.
This PR proposes to add the `ready` macro as `core::ready`. But another option would be to introduce it as `core::task::ready` since it's really only useful when used in conjunction with `task::{Context, Poll}`.
## Implementation questions
I tried rendering the documentation locally but the macro didn't show up under `core`. I'm not sure if I quite got this right. I used the [`todo!` macro PR](https://github.com/rust-lang/rust/pull/56348/files) as a reference, and our approaches look similar.
## References
- [`futures::ready`](https://docs.rs/futures/0.3.4/futures/macro.ready.html)
- [`async_std::task::ready`](https://docs.rs/async-std/1.5.0/async_std/task/index.html)
- [`futures_core::ready`](https://docs.rs/futures-core/0.3.4/futures_core/macro.ready.html)
Diffstat (limited to 'library/std/src/sys/unix/stack_overflow.rs')
0 files changed, 0 insertions, 0 deletions
