summaryrefslogtreecommitdiff
path: root/src/rwlock/rwlock.rs
diff options
context:
space:
mode:
authorMica White <botahamec@gmail.com>2024-12-25 11:17:35 -0500
committerMica White <botahamec@gmail.com>2024-12-25 11:17:35 -0500
commit657377311d3b041ac7b942e61ddbbe2861c494ec (patch)
tree5e041812c67e7ef0451b35d0b33ee90be28fbeaf /src/rwlock/rwlock.rs
parent7e2a3aa417beb33c76fe98fbe49515c524cb0183 (diff)
try_lock returns a Result
Diffstat (limited to 'src/rwlock/rwlock.rs')
-rw-r--r--src/rwlock/rwlock.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/rwlock/rwlock.rs b/src/rwlock/rwlock.rs
index 03b2cfd..b5dea75 100644
--- a/src/rwlock/rwlock.rs
+++ b/src/rwlock/rwlock.rs
@@ -286,13 +286,13 @@ impl<T: ?Sized, R: RawRwLock> RwLock<T, R> {
pub fn try_read<'s, 'key: 's, Key: Keyable>(
&'s self,
key: Key,
- ) -> Option<RwLockReadGuard<'s, 'key, T, Key, R>> {
+ ) -> Result<RwLockReadGuard<'s, 'key, T, Key, R>, Key> {
unsafe {
if self.raw_try_read() {
// safety: the lock is locked first
- Some(RwLockReadGuard::new(self, key))
+ Ok(RwLockReadGuard::new(self, key))
} else {
- None
+ Err(key)
}
}
}
@@ -381,13 +381,13 @@ impl<T: ?Sized, R: RawRwLock> RwLock<T, R> {
pub fn try_write<'s, 'key: 's, Key: Keyable>(
&'s self,
key: Key,
- ) -> Option<RwLockWriteGuard<'s, 'key, T, Key, R>> {
+ ) -> Result<RwLockWriteGuard<'s, 'key, T, Key, R>, Key> {
unsafe {
if self.raw_try_lock() {
// safety: the lock is locked first
- Some(RwLockWriteGuard::new(self, key))
+ Ok(RwLockWriteGuard::new(self, key))
} else {
- None
+ Err(key)
}
}
}