3 ms·
Pin, Unpin, and why Rust needs them
- brundolf 5y agoThis is good info, but I don't fully understand why pinning makes self-references safe. I thought the problem with self-references was that they interfere with single-ownership, which is required for automatic deallocation? I guess maybe if direct self-referencing is a distinct case from indirect self-referencing then it might not be problematic for single-ownership?
- deleted 5y ago[deleted]
- pixel_fcker 5y agoThe problem with self-references is that if you move the containing struct then the reference is now invalid. Pinning the object so it can’t move works around this.
- antonin42 5y agoI don’t know enough about Rust I always think about passing these self referencing structure by reference in other languages.
- remram 5y agoUsing the `async fn` syntax, this whole wrapper becomes: async fn time_future<Fut: Future>(fut: Fut) -> (Fut::Output, Duration) { let start = Instant::now(); let result = fut.await; (result, start.elapsed()) }
- adamch 5y agoYes, this is just a simplification of the real problem I was solving: docs.rs/restartables