82beeabf54
Add section on common message styles for Result::expect Based on a question from https://github.com/rust-lang/project-error-handling/issues/50#issuecomment-1092339937 ~~One thing I haven't decided on yet, should I duplicate this section on `Option::expect`, link to this section, or move it somewhere else and link to that location from both docs?~~: I ended up moving the section to `std::error` and referencing it from both `Result::expect` and `Option::expect`'s docs. I think this section, when combined with the similar update I made on [`std::panic!`](https://doc.rust-lang.org/nightly/std/macro.panic.html#when-to-use-panic-vs-result) implies that we should possibly more aggressively encourage and support the "expect as precondition" style described in this section. The consensus among the libs team seems to be that panic should be used for bugs, not expected potential failure modes. The "expect as error message" style seems to align better with the panic for unrecoverable errors style where they're seen as normal errors where the only difference is a desire to kill the current execution unit (aka erlang style error handling). I'm wondering if we should be providing a panic hook similar to `human-panic` or more strongly recommending the "expect as precondition" style of expect message. |
||
---|---|---|
.. | ||
alloc | ||
array | ||
async_iter | ||
char | ||
convert | ||
ffi | ||
fmt | ||
future | ||
hash | ||
iter | ||
macros | ||
mem | ||
num | ||
ops | ||
panic | ||
prelude | ||
ptr | ||
slice | ||
str | ||
sync | ||
task | ||
unicode | ||
any.rs | ||
ascii.rs | ||
asserting.rs | ||
bool.rs | ||
borrow.rs | ||
cell.rs | ||
clone.rs | ||
cmp.rs | ||
default.rs | ||
hint.rs | ||
internal_macros.rs | ||
intrinsics.rs | ||
lazy.rs | ||
lib.rs | ||
marker.rs | ||
option.rs | ||
panic.rs | ||
panicking.rs | ||
pin.rs | ||
primitive_docs.rs | ||
primitive.rs | ||
result.rs | ||
time.rs | ||
tuple.rs | ||
unit.rs |