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
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.
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
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.
Great post! I'd enjoy seeing more breakdowns of interesting snippets from Zed. I enjoy your Joy & Curiosity posts a lot as well.