Learning to program in rust
dejected_warp_core @ dejected_warp_core @lemmy.world Posts 2Comments 1,135Joined 2 yr. ago
dejected_warp_core @ dejected_warp_core @lemmy.world
Posts
2
Comments
1,135
Joined
2 yr. ago
This is basically where my learning took me. I had to develop this notion that there was a preferred directionality to ownership and data flow, like "grain" in a piece of wood. Everything is easier if you go with the grain. "Tree-shaped" works too, since it basically is the call graph of a (single threaded) program.
The point where I realized all this was when I tried to do a very Python/JS-brained thing: return a closure from a function. The moment you try to "curry" values into the closure, you have to "move" them to solve for ownership, lest you bring timelines into the picture. Which isn't always what you want in a generic and reusable function. And sure enough, the standard lib and other popular libraries want you to pass a closure to functions instead.