You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of rust-lang#118087 - GrigorenkoPV:refcell_try_map, r=Mark-Simulacrum
Add Ref/RefMut try_map method
Tracking issue: rust-lang#143801
A more generalized version of [`filter_map`](https://doc.rust-lang.org/stable/core/cell/struct.Ref.html#method.filter_map), which allows to return some data on failure.
## Safety
As far as I can tell, `E` cannot contain any `'b` data, so it is impossible to duplicate the `&'b [mut]` reference into the `RefCell`'s data.
Other than this `E`, everything is analogous to the already stable `filter_map`.
## `Try` / `Residual`
I have considered generalizing this to use the `Try` & `Residual` just like rust-lang#79711 does for `array::try_map`, but it does not seem to be possible: we want to essentially `.map_err(|e| (orig, e))` but this does not seem to be supported with `Try`. (Plus I am not even sure if it is possible to express the fact that `&U` in `Try::Output` would have to have the same lifetime as the `&T` input of `F`.)
## ACP
~As far as I can tell, this [is not mandatory](https://std-dev-guide.rust-lang.org/development/feature-lifecycle.html#suitability-for-the-standard-library), and the implementation is small enough to probably be smaller than the doc I would have to write.~
~rust-lang/libs-team#341rust-lang/libs-team#586
0 commit comments