-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added either::map_both, either:try_map_both #109
base: main
Are you sure you want to change the base?
Conversation
@cuviper Ready for the review! |
This functionality already exists privately as Lines 133 to 140 in 53ae3de
So the internal use is evidence enough that this is a useful macro. The existing macro is named like the Please do update the existing uses to |
I'm less sure about your new addition of |
I'm not sure how to implement it properly given that https://doc.rust-lang.org/beta/std/ops/trait.Try.html is unstable.
And it is an amazing idea. |
I'll have to start working just in 3 minutes, so I'll probably be able to come back to it only in the evening! Still, thank you a lot for the feedback! |
Right, you can't, which gives the advantage to the |
I reimplemented the code using a hidden and sealed Once For the time being, it works with a |
@cuviper Ready for the second review! |
There are a small annoyances that make me want to have a dedicated
|
Hidden closures in the macro also have costs, since that prevents control flow and some borrowck patterns that would otherwise be allowed in local code. Have you considered |
Where can I learn more about that problem? It feels more like an issue with the compiler than with the idea.
And I guess it'll work but |
The control flow limitation is straightforward -- stuff like For borrowck, the biggest difference I can think of is with initialization. You can move locals into a closure capture without trouble, but you can't move them back to re-initialize the local, nor can you initialize it for the first time. Without a closure, borrowck is able to track discontinuous regions where a local is initialized. |
FWIW, I do have a private Here, we're talking about a convenience macro for a relatively simple |
Added an additional line to the doc of
either::for_both!
:Implementation of
map_both!
Implementation of
try_map_both!
:P.S.
If you have an idea for a simple and meaningful example for
try_map_both!
, it will be very welcome!