(no title)
aaronjanse | 5 years ago
`expect` takes an input that is either an error or a value, then turns that input into just a value. The provided string is the error message if something goes wrong (i.e. the input was an error).
aaronjanse | 5 years ago
`expect` takes an input that is either an error or a value, then turns that input into just a value. The provided string is the error message if something goes wrong (i.e. the input was an error).
einpoklum|5 years ago
Measter|5 years ago
You would typically use `expect` (or `unwrap`, which does the same thing but without a custom message) when you either know for certain that it can't fail, or the failure condition is not something the program can recover from.
[0] Full definition can be found at https://doc.rust-lang.org/std/result/enum.Result.html
[1] Technically, you can catch a panic unwind [2], but it's more awkward and intended more for FFI boundaries than normal code. There's also no guarantee that the program will unwind. The compiler might have been set to abort on a panic instead of unwinding, in which case there's no unwind to catch.
[2] https://doc.rust-lang.org/std/panic/fn.catch_unwind.html