|
|
|
|
|
by southerntofu
1505 days ago
|
|
> What do you do in Rust , do you check the return result and on top of that do you try to catch a panic just in case the regex library is bugged ? Nope, we just check the return result because libraries usually don't crash and have well-defined error cases. Having a decent type system helps catching all the possible outcomes. In a few years coding Rust, i never had a single crash due to a library panic, only from explicit unwraps i applied in my own codebase. Panics are not intended for errors, but for unrecoverable failures. For example, in rust std a failing memory allocation will crash your whole program, which is in most cases what you want to do. For the remaining cases, there are other non-fallible methods. For example: String::reserve vs String::try_reserve or HashMap::insert vs HashMap::try_insert. |
|