-
Couldn't load subscription status.
- Fork 13.9k
Closed
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
Feature gate: #![feature(cell_filter_map)]
This is a tracking issue for Ref::filter_map and RefMut::filter_map, which lets you optionally project data inside a Ref or RefMut, wrapped in a Ref or RefMut. If the projection returns None then these methods return a Err(Self) so that you can still get the original Ref or RefMut back out.
Public API
impl<'b, T: ?Sized> Ref<'b, T> {
pub fn filter_map<U: ?Sized, F>(orig: Ref<'b, T>, f: F) -> Result<Ref<'b, U>, Self>
where
F: FnOnce(&T) -> Option<&U> {}
}
impl<'b, T: ?Sized> RefMut<'b, T> {
pub fn filter_map<U: ?Sized, F>(orig: RefMut<'b, T>, f: F) -> Result<RefMut<'b, U>, Self>
where
F: FnOnce(&mut T) -> Option<&mut U> {}
}Steps / History
- Implementation: Introduce {Ref, RefMut}::try_map for optional projections in RefCell #78455
- Final commenting period (FCP)
- Stabilization PR
Unresolved Questions
- Naming and signature: We wanted to call this method
try_mapand accept a closure likeFnOnce(&T) -> R where R: Try<Ok = &U>, but that's not sound with bound lifetimes. This method is only ok when the mapping closure uses HRTB. So we opted to call itfilter_mapinstead, with the closure returning aOption<&U>.
davidhalter and wkordalski
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.