junderwood4649 on Nostr: Rust closures and async blocks can only be referenced using generic trait bounds or ...
Rust closures and async blocks can only be referenced using generic trait bounds or dynamic dispatch.
It seems like there's a pattern in Rust of the APIs with the most magic being the hardest to understand. Especially if they use anonymous structs under the hood.
Someone had two-level nested move closures and the innermost one was FnMut (called more than once) and they tried to move something from the outermost scope.
The problem being, once it goes in the first closure, it becomes an owned member of the outer closure, so you get errors about partial moves when moving into the inner closure.
Not sure how the errors could be made better, but even I couldn't really explain it to my friend without explaining closures in detail and how they work.
Rust is amazing once you get the hang of it, but oh boy does it take a while to get used to some of the oddities.
Published at
2023-01-27 20:12:27Event JSON
{
"id": "50ef2d94aea8009a5b97b7858f9ffafdedf524487b563be827549c7d49a92473",
"pubkey": "ac6833cc33f834ac97254cfcc8264c03e8fd7c944b31e1ff0b98b1eb65a33356",
"created_at": 1674850347,
"kind": 1,
"tags": [],
"content": "Rust closures and async blocks can only be referenced using generic trait bounds or dynamic dispatch.\n\nIt seems like there's a pattern in Rust of the APIs with the most magic being the hardest to understand. Especially if they use anonymous structs under the hood.\n\nSomeone had two-level nested move closures and the innermost one was FnMut (called more than once) and they tried to move something from the outermost scope.\n\nThe problem being, once it goes in the first closure, it becomes an owned member of the outer closure, so you get errors about partial moves when moving into the inner closure.\n\nNot sure how the errors could be made better, but even I couldn't really explain it to my friend without explaining closures in detail and how they work.\n\nRust is amazing once you get the hang of it, but oh boy does it take a while to get used to some of the oddities.\n",
"sig": "79f733f960eae11f9b35db6b4de02950abebeabd5462e347952f4055f5459a2cc695d1a5e47cf978bebbdab1fe06fee0d1d243367bf8dd6e7d5a0a229dd672ef"
}