Compare commits

...

4 Commits

Author SHA1 Message Date
Eric Holk 9c300510c4
Merge pull request #190 from hydra/add-pinning-compilation-error-details
Pinning - Add details of the compiler errors that occur when trying to use get_mut().
2023-03-30 10:50:05 -07:00
Eric Holk 41023fbb55
Merge pull request #194 from bravequickcleverfibreyarn/6_3_select_example
Obviously old comment removal
2023-03-30 10:47:56 -07:00
JirCep fc9038c140 Obviously old comment removal 2023-02-13 22:25:41 +01:00
Dominic Clifton 70ef3c1c68 Add details of the compiler errors that occur when trying to use get_mut(). 2023-02-01 18:29:55 +01:00
2 changed files with 21 additions and 8 deletions

View File

@ -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,

View File

@ -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`