failure icon indicating copy to clipboard operation
failure copied to clipboard

Add a shorthand for Option::ok_or_else with err_msg

Open killercup opened this issue 7 years ago • 3 comments

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 https://github.com/killercup/quicli/pull/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.

killercup avatar Jan 29 '18 09:01 killercup

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

withoutboats avatar Jan 29 '18 09:01 withoutboats

Yeah, good point. There's no rush, I'm okay with landing this in quicli itself (once I have a concrete use case) and switching to exporting the upstream version later on.

Am 29.01.2018 um 10:41 schrieb boats [email protected]:

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

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

killercup avatar Jan 29 '18 09:01 killercup

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.

stevedonovan avatar Feb 26 '18 13:02 stevedonovan