Added either::map_both, either:try_map_both#109
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 |
|
@JohnScience there's a new request for I think the "try" part would be better left separate, possibly once |
|
@cuviper I pivoted from Software Engineering to Sales. I kinda hated the job market. If there's a free day (I don't really have days off), I might come back and do something about it. However, it might take me up to 6 months to be really free. Good luck tho! |
|
@cuviper would you like me to file another PR with just |
|
@ronnodas go ahead if you want -- I think you could even cherry-pick from this PR without the "try" commits, as they look reasonably separate. |
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!