diff options
| author | Mica White <botahamec@gmail.com> | 2024-12-25 11:17:35 -0500 |
|---|---|---|
| committer | Mica White <botahamec@gmail.com> | 2024-12-25 11:17:35 -0500 |
| commit | 657377311d3b041ac7b942e61ddbbe2861c494ec (patch) | |
| tree | 5e041812c67e7ef0451b35d0b33ee90be28fbeaf /src/rwlock | |
| parent | 7e2a3aa417beb33c76fe98fbe49515c524cb0183 (diff) | |
try_lock returns a Result
Diffstat (limited to 'src/rwlock')
| -rw-r--r-- | src/rwlock/read_lock.rs | 2 | ||||
| -rw-r--r-- | src/rwlock/rwlock.rs | 12 | ||||
| -rw-r--r-- | src/rwlock/write_lock.rs | 2 |
3 files changed, 8 insertions, 8 deletions
diff --git a/src/rwlock/read_lock.rs b/src/rwlock/read_lock.rs index c5c4c8c..e518cf3 100644 --- a/src/rwlock/read_lock.rs +++ b/src/rwlock/read_lock.rs @@ -72,7 +72,7 @@ impl<T: ?Sized, R: RawRwLock> ReadLock<'_, T, R> { pub fn try_lock<'s, 'key: 's, Key: Keyable + 'key>( &'s self, key: Key, - ) -> Option<RwLockReadGuard<'s, 'key, T, Key, R>> { + ) -> Result<RwLockReadGuard<'s, 'key, T, Key, R>, Key> { self.0.try_read(key) } 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) } } } diff --git a/src/rwlock/write_lock.rs b/src/rwlock/write_lock.rs index 77b68c8..ba05e87 100644 --- a/src/rwlock/write_lock.rs +++ b/src/rwlock/write_lock.rs @@ -73,7 +73,7 @@ impl<T: ?Sized, R: RawRwLock> WriteLock<'_, T, R> { pub fn try_lock<'s, 'key: 's, Key: Keyable + 'key>( &'s self, key: Key, - ) -> Option<RwLockWriteGuard<'s, 'key, T, Key, R>> { + ) -> Result<RwLockWriteGuard<'s, 'key, T, Key, R>, Key> { self.0.try_write(key) } |
