-
Notifications
You must be signed in to change notification settings - Fork 553
Commit d113c70
authored
Rollup merge of #118087 - GrigorenkoPV:refcell_try_map, r=Mark-Simulacrum
Add Ref/RefMut try_map method
Tracking issue: rust-lang/rust#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/rust#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#341
rust-lang/libs-team#586File tree
Expand file treeCollapse file tree
0 file changed
+0
-0
lines changedFilter options
Expand file treeCollapse file tree
0 file changed
+0
-0
lines changed
0 commit comments