-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Open
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.
Description
Feature gate: #![feature(mapped_lock_guards)]
This is a tracking issue for MappedMutexGuard, MappedRwLockReadGuard, and MappedRwLockWriteGuard.
This adds types analogous to lock_api::MappedMutexGuard, MappedRwLockReadGuard, MappedRwLockWriteGuard) to std::sync, and methods MutexGuard::map and MutexGuard::filter_map (same for `RwLock*Guard) to create them
Public API
// std::sync::mutex
pub struct MappedMutexGuard<'mutex, T: ?Sized>;
impl<'mutex, T: ?Sized> MutexGuard<'mutex, T> {
pub fn map<U, F>(orig: Self, f: F) -> MappedMutexGuard<'mutex, U>
where
F: FnOnce(&mut T) -> &mut U,
U: ?Sized;
pub fn filter_map<U, F>(orig: Self, f: F) -> Result<MappedMutexGuard<'mutex, U>, Self>
where
F: FnOnce(&mut T) -> Option<&mut U>,
U: ?Sized;
}
impl<'mutex, T: ?Sized> MappedMutexGuard<'mutex, T> {
pub fn map<U, F>(orig: Self, f: F) -> MappedMutexGuard<'mutex, U>
where
F: FnOnce(&mut T) -> &mut U,
U: ?Sized;
pub fn filter_map<U, F>(orig: Self, f: F) -> Result<MappedMutexGuard<'mutex, U>, Self>
where
F: FnOnce(&mut T) -> Option<&mut U>,
U: ?Sized;
}
impl<T: ?Sized> Deref/DerefMut for MappedMutexGuard<'_, T>;
impl<T: ?Sized + Debug/Display> Debug/Display for MappedMutexGuard<'_, T>;// std::sync::rwlock
pub struct MappedRwLockReadGuard<'rwlock, T: ?Sized>;
pub struct MappedRwLockWriteGuard<'rwlock, T: ?Sized>;
impl<'rwlock, T: ?Sized> RwLockReadGuard<'rwlock, T> {
pub fn map<U, F>(orig: Self, f: F) -> MappedRwLockReadGuard<'rwlock, U>
where
F: FnOnce(&T) -> &U,
U: ?Sized;
pub fn filter_map<U, F>(orig: Self, f: F) -> Result<MappedRwLockReadGuard<'rwlock, U>, Self>
where
F: FnOnce(&T) -> Option<&U>,
U: ?Sized;
}
impl<'rwlock, T: ?Sized> MappedRwLockReadGuard<'rwlock, T> {
pub fn map<U, F>(orig: Self, f: F) -> MappedRwLockReadGuard<'rwlock, U>
where
F: FnOnce(&T) -> &U,
U: ?Sized;
pub fn filter_map<U, F>(orig: Self, f: F) -> Result<MappedRwLockReadGuard<'rwlock, U>, Self>
where
F: FnOnce(&T) -> Option<&U>,
U: ?Sized;
}
impl<'rwlock, T: ?Sized> RwLockWriteGuard<'rwlock, T> {
pub fn map<U, F>(orig: Self, f: F) -> MappedRwLockWriteGuard<'rwlock, U>
where
F: FnOnce(&mut T) -> &mut U,
U: ?Sized;
pub fn filter_map<U, F>(orig: Self, f: F) -> Result<MappedRwLockWriteGuard<'rwlock, U>, Self>
where
F: FnOnce(&mut T) -> Option<&mut U>,
U: ?Sized;
}
impl<'rwlock, T: ?Sized> MappedRwLockWriteGuard<'rwlock, T> {
pub fn map<U, F>(orig: Self, f: F) -> MappedRwLockWriteGuard<'rwlock, U>
where
F: FnOnce(&mut T) -> &mut U,
U: ?Sized;
pub fn filter_map<U, F>(orig: Self, f: F) -> Result<MappedRwLockWriteGuard<'rwlock, U>, Self>
where
F: FnOnce(&mut T) -> Option<&mut U>,
U: ?Sized;
}
impl<T: ?Sized> Deref for MappedRwLockReadGuard<'_, T>;
impl<T: ?Sized> Deref/DerefMut for MappedRwLockWriteGuard<'_, T>;
impl<T: ?Sized + Debug/Display> Debug/Display for MappedRwLockReadGuard<'_, T>;
impl<T: ?Sized + Debug/Display> Debug/Display for MappedRwLockWriteGuard<'_, T>;Steps / History
- ACP: Include MappedRwLocKWriteGuard from lock_api or parking_lot libs-team#260
- Implementation: Implement
MappedMutexGuard,MappedRwLockReadGuard, andMappedRwLockWriteGuard. #117107 - Rename
try_maptofilter_map: Rename*Guard::try_maptofilter_map. #140536 - Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- None yet.
Footnotes
anko, Fuuzetsu, Stargateur, Scripter17, PonasKovas and 17 moretjallingt, connorslade, eareimu, PonasKovas, EriKWDev and 2 more
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.