The whole example of juggling Pin in the futures executor section is a great example of how assumptions in the design of programming languages can have unexpectedly far-reaching effects. Rust’s borrow checker assumes that things in memory generally don’t move: copies are explicit, if an object is moved between variables then it is actually memcpy’d from one struct or variable to another, and it may live on the stack for a particular function or in thread local storage for a thread that might go away or strange stuff like that.. This means that when you create a piece of state, like a future, and hand it off to something that may or may not execute it on a different thread and free it, then the question of where the object is actually supposed to be is nontrivial and you need to be very meticulous about explaining to the language what’s going on.
Contrast this with async in languages that have a garbage collector, like C#. Most objects are boxed on the heap and you seldom actually move them around, you just pass around pointers to them. The things that aren’t on the heap and so might have a weird lifetime usually can’t have pointers to them created, a la C#’s struct’s (if I am remembering correctly). This means that moving objects around in memory is very easy and the garbage collector can do it whenever it feels like it, since it already knows how to fix up all pointers in the program to point to the new object. So, storing the state for an async state machine and handing it around to different threads or executors or whatever needs very little additional work compared to just writing a function, because all the framework for dynamically tracking lifetimes is already there.
There’s a reason that programming language design from 1995 to 2015 tried to make garbage collection good enough to be universal and boxed every object possible: it makes some very nice simplifying assumptions possible.
2 minutes in and it already sold me on the fact that I need to step up my rust logging and backtracing game, how could I even live with non-colored backtraces and unstructured logging