Open
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
Unresolved Questions
- None yet.
Footnotes
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
MappedMutexGuard
,MappedRwLockReadGuard
, andMappedRwLockWriteGuard
. #117107Auto merge of rust-lang#117107 - zachs18:mapped-mutex-guard, r=Amanieu
Auto merge of #117107 - zachs18:mapped-mutex-guard, r=Amanieu
Auto merge of #117107 - zachs18:mapped-mutex-guard, r=Amanieu
Auto merge of #117107 - zachs18:mapped-mutex-guard, r=Amanieu
Global
a bit godot-rust/gdext#750Fuuzetsu commentedon Jun 20, 2024
Is there anything needed to start FCP? Seems it's all implemented and just waiting around.
Earthcomputer commentedon Jul 2, 2024
I think it's this, there has been activity on zulip about this since that comment.
RaitoBezarius commentedon Sep 6, 2024
From the Zulip activity, it seems like this has nothing to do with mapped lock guards, or am I missing something?
sync_nonpoison
andnonpoison_{condvar,mutex,once,rwlock}
#134645tgross35 commentedon Dec 22, 2024
This feature adds three structs and we would get three more with the
nonpoison
module (#134645), plus one more forReentrantLockGuard
(#121440). What if instead we added a perma-unstableLockGuard
trait and then replaced theseMapped*Guard
types with a singlestruct Mapped<G: LockGuard> { /* ... */ }
? This would save us from having the same user-facing API repeated in seven different locations.ultimaweapon commentedon Jan 9, 2025
With the above API how to use with a method that return a value instead of a reference? e.g.:
12 remaining items