Skip to content
SOFTWARE ENGINEERING AND PROGRAMMING

Why Rust should only have provided `expect` for turning errors into panics, and not also provided `unwrap`

UPDATE 3 (from 2025): I don’t really believe this anymore. UPDATE 2: I have made the title longer because people seem to be insisting on misunderstanding me, giving examples where the only reasonable thing to do is to escalate an Err into a panic. Indeed, such situations exist. I am not advocating for panic-free code. I am advocating that expect should be used for those functions, and if a function is particularly prone to being called like that (e.g. Mutex::lock or regex compilation), there should be a panicking version.
ANDREW GALLANT