summaryrefslogtreecommitdiff
path: root/src/lockable.rs
diff options
context:
space:
mode:
authorBotahamec <botahamec@outlook.com>2024-09-26 22:58:13 -0400
committerBotahamec <botahamec@outlook.com>2024-09-26 22:58:13 -0400
commit2376ccee97c99d5c47c09fcf308a97aaf785a29e (patch)
tree0aa7814c78a035929d494f60dec5daa925bed433 /src/lockable.rs
parent5f55113a6ead937fc8bc81e361abc09b3a1565f3 (diff)
Better into_inner and get_mut implementations
Diffstat (limited to 'src/lockable.rs')
-rw-r--r--src/lockable.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/lockable.rs b/src/lockable.rs
index 9f44981..6eced32 100644
--- a/src/lockable.rs
+++ b/src/lockable.rs
@@ -151,6 +151,18 @@ pub unsafe trait Lockable {
unsafe fn read_guard(&self) -> Self::ReadGuard<'_>;
}
+pub trait LockableIntoInner: Lockable {
+ type Inner;
+
+ fn into_inner(self) -> Self::Inner;
+}
+
+pub trait LockableAsMut: Lockable {
+ type Inner;
+
+ fn as_mut(&mut self) -> &mut Self::Inner;
+}
+
/// A marker trait to indicate that multiple readers can access the lock at a
/// time.
///
@@ -258,6 +270,38 @@ unsafe impl<T: Send, R: RawRwLock + Send + Sync> Lockable for RwLock<T, R> {
}
}
+impl<T: Send, R: RawMutex + Send + Sync> LockableIntoInner for Mutex<T, R> {
+ type Inner = T;
+
+ fn into_inner(self) -> Self::Inner {
+ self.into_inner()
+ }
+}
+
+impl<T: Send, R: RawMutex + Send + Sync> LockableAsMut for Mutex<T, R> {
+ type Inner = T;
+
+ fn as_mut(&mut self) -> &mut Self::Inner {
+ self.get_mut()
+ }
+}
+
+impl<T: Send, R: RawRwLock + Send + Sync> LockableIntoInner for RwLock<T, R> {
+ type Inner = T;
+
+ fn into_inner(self) -> Self::Inner {
+ self.into_inner()
+ }
+}
+
+impl<T: Send, R: RawRwLock + Send + Sync> LockableAsMut for RwLock<T, R> {
+ type Inner = T;
+
+ fn as_mut(&mut self) -> &mut Self::Inner {
+ AsMut::as_mut(self)
+ }
+}
+
unsafe impl<T: Send, R: RawRwLock + Send + Sync> Sharable for RwLock<T, R> {}
unsafe impl<T: Send, R: RawMutex + Send + Sync> OwnedLockable for Mutex<T, R> {}