Hacker News new | ask | show | jobs
by tov_objorkin 2376 days ago
unwrap() or expect() unconditionally smash program execution in case of error. Properly written program should handle such errors or use unwrap_or_* as fallback. The point is that unwrap/unsafe is breaking safety rules, user writing one know what hes doing or just don't bothering.
1 comments

Unwrap and expect don’t violate any safety rules! If they did you’d need to wrap it in an unsafe block.

https://doc.rust-lang.org/nomicon/unwinding.html

You're technically right, i mean if user aim for durable code then using unwrap is not desired behavior most of the time. For example pointer deference in C is implicit operation. In Rust user must choose explicitly how to handle Option/Result. Even if using unwrap not so harmful as using unsafe and didn't violate rules this is our deliberate choose to break "end-user safety".