5 ms·
You have it wrong. Only the most basic code on Earth has unwrap in it. Real-world code will either actually handle the error with `match`, forward it with `?`,
by crematoria 7y ago
You have it wrong. Only the most basic code on Earth has unwrap in it. Real-world code will either actually handle the error with `match`, forward it with `?`, or unwrap it with `except` iff it's sure that an error will not occur.
- arghwhat 7y ago> https://github.com/servo/servo/search?q=unwrap&unscoped_q=unwrap https://github.com/servo/servo/search?q=unwrap&unscoped_q=un... 522 results in servo. Granted, some (but not all) are in tests. `.unwrap()` is expected to be in every code base out there, as there is rarely much point in handling errors such as tainted mutex locks.
- frenchman99 7y agoMost of the code you're linking to is unit tests, not application code.
- arghwhat 7y agoNo, I am thinking of application code. If you're trying to handle a poisoned mutex, you're doing something wrong.
- crematoria 7y agoYeah, most of that code is stuff like examples and tests, and most errors should be forwarded, not unwrapped. But yeah, of course if a resource that you depend on is potentially in an invalid state thanks to a thread crashing, it makes perfect sense to unwrap / expect.
- deleted 7y ago[deleted]