36
Dioxus Labs + “High-level Rust
(dioxus.notion.site)
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Credits
There are a few very questionable things in there. Unwrap should literally never appear in production code so if your code base uses it so often that you want a short-hand syntax for it that calls into doubt everything else you wrote.
Unwrap comes up all the time in the standard library.
For example, if you know you're popping from a non-empty vector, unwrap is totally the right too for the job. There are tons of circumstances where you know at higher levels that edge cases defended against at lower levels with
Optioncannot occur.(DISCLAIMER: I haven't read the post yet.)
That would/should be
.expect(). You register your assumption once, at the source level, and at the panic level if the assumption ever gets broken. And it's not necessarily a (local) logical error that may cause this. It could be a logical error somewhere else, or a broken running environment where sound logic is broken by hardware or external system issues.If you would be writing comments around your
.unwrap()s anyway (which you should be), then.expect()is a strictly superior choice.One could say
.unwrap()was a mistake. It's not even that short of a shortcut (typing wise). And the maximumly lazy could have always written.expect("")instead anyway.I personally think that unwrap and the question mark operator were a mistake.