Hacker News new | past | comments | ask | show | jobs | submit login
Pin, Unpin, and why Rust needs them (cloudflare.com)
37 points by jgrahamc 61 days ago | hide | past | favorite | 5 comments

This 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?

The 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.

I don’t know enough about Rust I always think about passing these self referencing structure by reference in other languages.

Using 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())

Yes, this is just a simplification of the real problem I was solving: docs.rs/restartables

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact