TIL #rustlang gift wrapping types provide `unwrap_or_default` https://doc.rust-lang.org/core/option/enum.Option.html#method.unwrap_or_default … https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap_or_default …. so useful! if you are used to `option.unwrap_or(Default::default())` like me, stop, there's a better way. consider this part of my #pleasedontcallunwrap campaign
-
-
Not always a bad thing but a bad habit is more of what I'm trying to get at
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
I think any unwrap should be replaced with an expect, usually specifying which invariant was broken.
-
I'm struggling with discipline here. Calls to expect will communicate a problem but communicate in a way what steps around the type system. Similar to throwing exceptions in languages like Java. I feel like a result type is a more considerate way to communicate errors for callers
- 1 more reply
New conversation -
-
-
Yup! You can use unwrap where you can guarantee as the programmer data is there, but the compiler can't prove that. It's not always a bad thing!
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
