mirror of https://github.com/rust-lang/async-book
Merge branch 'rust-lang:master' into spawning
This commit is contained in:
commit
87ac3cbdd3
|
@ -90,7 +90,7 @@ impl Executor {
|
|||
if let Some(mut future) = future_slot.take() {
|
||||
// Create a `LocalWaker` from the task itself
|
||||
let waker = waker_ref(&task);
|
||||
let context = &mut Context::from_waker(&*waker);
|
||||
let context = &mut Context::from_waker(&waker);
|
||||
// `BoxFuture<T>` is a type alias for
|
||||
// `Pin<Box<dyn Future<Output = T> + Send + 'static>>`.
|
||||
// We can get a `Pin<&mut dyn Future + Send + 'static>`
|
||||
|
|
|
@ -140,13 +140,6 @@ async fn get_new_num() -> u8 { /* ... */ 5 }
|
|||
|
||||
async fn run_on_new_num(_: u8) -> u8 { /* ... */ 5 }
|
||||
|
||||
// Runs `run_on_new_num` with the latest number
|
||||
// retrieved from `get_new_num`.
|
||||
//
|
||||
// `get_new_num` is re-run every time a timer elapses,
|
||||
// immediately cancelling the currently running
|
||||
// `run_on_new_num` and replacing it with the newly
|
||||
// returned value.
|
||||
async fn run_loop(
|
||||
mut interval_timer: impl Stream<Item = ()> + FusedStream + Unpin,
|
||||
starting_num: u8,
|
||||
|
|
|
@ -7,5 +7,5 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies.async-std]
|
||||
version = "1.6"
|
||||
version = "1.12"
|
||||
features = ["attributes"]
|
||||
|
|
|
@ -7,5 +7,5 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies.async-std]
|
||||
version = "1.6"
|
||||
version = "1.12"
|
||||
features = ["attributes"]
|
||||
|
|
|
@ -10,5 +10,5 @@ edition = "2021"
|
|||
futures = "0.3"
|
||||
|
||||
[dependencies.async-std]
|
||||
version = "1.6"
|
||||
version = "1.12"
|
||||
features = ["attributes"]
|
||||
|
|
|
@ -10,5 +10,5 @@ edition = "2021"
|
|||
futures = "0.3"
|
||||
|
||||
[dependencies.async-std]
|
||||
version = "1.6"
|
||||
version = "1.12"
|
||||
features = ["attributes"]
|
||||
|
|
|
@ -480,7 +480,27 @@ pub fn main() {
|
|||
# }
|
||||
```
|
||||
|
||||
The type system prevents us from moving the data.
|
||||
The type system prevents us from moving the data, as follows:
|
||||
|
||||
```
|
||||
error[E0277]: `PhantomPinned` cannot be unpinned
|
||||
--> src\test.rs:56:30
|
||||
|
|
||||
56 | std::mem::swap(test1.get_mut(), test2.get_mut());
|
||||
| ^^^^^^^ within `test1::Test`, the trait `Unpin` is not implemented for `PhantomPinned`
|
||||
|
|
||||
= note: consider using `Box::pin`
|
||||
note: required because it appears within the type `test1::Test`
|
||||
--> src\test.rs:7:8
|
||||
|
|
||||
7 | struct Test {
|
||||
| ^^^^
|
||||
note: required by a bound in `std::pin::Pin::<&'a mut T>::get_mut`
|
||||
--> <...>rustlib/src/rust\library\core\src\pin.rs:748:12
|
||||
|
|
||||
748 | T: Unpin,
|
||||
| ^^^^^ required by this bound in `std::pin::Pin::<&'a mut T>::get_mut`
|
||||
```
|
||||
|
||||
> It's important to note that stack pinning will always rely on guarantees
|
||||
> you give when writing `unsafe`. While we know that the _pointee_ of `&'a mut T`
|
||||
|
|
Loading…
Reference in New Issue