Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Add a shorthand for Option::ok_or_else with err_msg #142

Open
killercup opened this issue Jan 29, 2018 · 3 comments
Open

Add a shorthand for Option::ok_or_else with err_msg #142

killercup opened this issue Jan 29, 2018 · 3 comments

Comments

@killercup
Copy link

I've been thinking of adding a .none_means(msg) (name bikeshed welcome) method to Option which expands .ok_or_else(|| err_msg(msg)). You can use it similar to .expect but returns an error instead of panicking.

I've implemented this in killercup/quicli#25 where you can also find a bit of discussion. If this is something you want to have upstream, i.e., in failure, let me know.

@withoutboats
Copy link
Contributor

Seems like a useful method. Not really sure if anyone will import an OptionExt trait just for this method though. :-\

@killercup
Copy link
Author

killercup commented Jan 29, 2018 via email

@stevedonovan
Copy link

It makes sense to implement OptionExt (did it the other day, easy) and that the method be called context. Arguably, only saves a few keystrokes but the result looks much clearer.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants