-
Notifications
You must be signed in to change notification settings - Fork 111
Adding a new OptionExt trait? #151
Comments
Yes! Though, could you first try to |
Here's my first draft at the feature--I still need to write tests, and try integrating it throughout my code. Does that look good to you WRT to how I used |
You can use |
So, you're saying to use |
Yes, that's it. It does the same thing: https://brson.github.io/error-chain/src/error_chain/error_chain.rs.html#121-126 |
Here's my updated changes: dgrnbrg@d02131f I'm using I've also included a new method Finally, you can see the commented out code I wrote which would allow for |
Sorry for the delay. Seems nice. Could you open a PR? |
I'm closing this in favor of the corresponding PR #156. |
Hello, I'm interested in contributing a new Ext trait for Option, so that I can have
chain_err
on options when they'reNone
. Often in my code I am working with a vector or iterator that should have a certain number of elements, and I want to bail when that's not the case. Currently, I have tons ofoption.ok_or(Error::from(format!("problem because of {:?}", context)))?
throughout my code, and I think it'd be cool to be able to instead do:option.chain_err(|| format!("problem beause of {:?}", context))
. That way, I wouldn't need to compute the error in the success case, and I'd delegate the error casting to type inference. Would you accept this as a PR?The text was updated successfully, but these errors were encountered: