4 Comments
User's avatar
Vincent Carlson's avatar

I love how you've broken down the complexities of Rust! It reminds me of when I first tackled Geometry Dash Lite—both require patience and a bit of trial and error to get those "aha" moments. Keep it up https://geometrydashlite2.io!

Aaron Tagliaboschi's avatar

That's a bunch of neat ideas crammed into a few lines. The question mark operator is briefly mentioned and the Rust book, but it's a really nice pinch of syntactic sugar. And the defer object is so brilliant I'm genuinely surprised it's not in std.

I will say that overriding "Result" rubs me the wrong way really strongly. Admittently I don't know if this is a more common thing in Rust but it smells kinda funny to me

Einar's avatar

It's very common for a module to provide their own Result alias -- you can always tell it's overridden because it only takes one type parameter instead of two. The standard library does this in several places -- see std::io::Result.

Defer is really genius. Even just using drop to do something that you normally need syntactic sugar for in other languages is very cool, but the ability to abort it is even more awesome.

Michael Krisher's avatar

Great post! I'd enjoy seeing more breakdowns of interesting snippets from Zed. I enjoy your Joy & Curiosity posts a lot as well.