3 ms·
`unwrap_or` and `expect` work exactly like they do in Rust. The naming of `expect` works nicely if the argument is the precondition that failed (see https://doc
by filmor 3y ago
`unwrap_or` and `expect` work exactly like they do in Rust. The naming of `expect` works nicely if the argument is the precondition that failed (see https://doc.rust-lang.org/std/error/index.html#common-message-styles https://doc.rust-lang.org/std/error/index.html#common-messag...), e.g.
.expect("should have opened file")
- pmontra 3y agoWith all the respect for a language that succeeded and the evidence that its choices are at least good enough, I think that they got it backwards. expect("the file is open") is a positive statement. expect("should have opened file") is a kind of negative and less easy to understand. They should have hinted the developers to use the correct style with a different method should("have opened file") That said, it did not hinder Rust, maybe it even contributed to its success so it's OK even if it feels strange to me. But unwrap is really an awkward word to pick.