An unwrap! macro crate

Here's a crate I wrote which I think is very handy, especially for tests and examples: GitHub - canndrew/unwrap: unwrap! macro for Rust

Please tell me what you think.

2 Likes

Cool, that's really helpful, thanks!
I'll try it out in one of my projects.

I use unwrap() quite often when testing things, after that I turn them into matches. Ideally stable code shouldn't have any unwrap() in it.

I use unwrap() quite often when testing things, after that I turn them into matches. Ideally stable code shouldn't have any unwrap() in it.

For the most part, I agree. There are couple of cases where it makes sense to use it in stable code though, for example when you want to propagate a panic by unwrapping the result of Mutex::lock or JoinHandle::join. Also rust's type system isn't perfect so sometimes it's possible to "know" that a certain condition can't occur yet there's no way to prove it within the type system. An example: you put a value in an Option and then immediately want to get a reference to that value.