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
Unresolved Questions
Feature gate:
#![feature(mapped_lock_guards)]This is a tracking issue for
MappedMutexGuard,MappedRwLockReadGuard, andMappedRwLockWriteGuard.This adds types analogous to
lock_api::MappedMutexGuard,MappedRwLockReadGuard,MappedRwLockWriteGuard) tostd::sync, and methodsMutexGuard::mapandMutexGuard::filter_map(same for `RwLock*Guard) to create themPublic API
Steps / History
MappedMutexGuard,MappedRwLockReadGuard, andMappedRwLockWriteGuard. #117107try_maptofilter_map: Rename*Guard::try_maptofilter_map. #140536Unresolved Questions
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩