diff options
| author | Mica White <botahamec@outlook.com> | 2024-03-11 17:17:31 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2024-03-11 17:17:31 -0400 |
| commit | 84ebd3cf9be21bba8eb6c4d214c868e66965b69a (patch) | |
| tree | 2b99f8523ebd10723f204ff5af43855ff408d05f /src/rwlock | |
| parent | 367ea452b09e1a0a8c67bb309073d37792bb748d (diff) | |
Add couple more docs
Diffstat (limited to 'src/rwlock')
| -rw-r--r-- | src/rwlock/rwlock.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/rwlock/rwlock.rs b/src/rwlock/rwlock.rs index 556d6bf..b1c7ff0 100644 --- a/src/rwlock/rwlock.rs +++ b/src/rwlock/rwlock.rs @@ -67,12 +67,42 @@ impl<T: ?Sized, R> AsMut<T> for RwLock<T, R> { } impl<T, R> RwLock<T, R> { + /// Consumes this `RwLock`, returning the underlying data. + /// + /// # Examples + /// + /// ``` + /// use happylock::{RwLock, ThreadKey}; + /// + /// let lock = RwLock::new(String::new()); + /// { + /// let key = ThreadKey::get().unwrap(); + /// let mut s = lock.write(key); + /// *s = "modified".to_owned(); + /// } + /// assert_eq!(lock.into_inner(), "modified"); + /// ``` pub fn into_inner(self) -> T { self.data.into_inner() } } impl<T: ?Sized, R> RwLock<T, R> { + /// Returns a mutable reference to the underlying data. + /// + /// Since this call borrows the `RwLock` mutably, no actual locking needs + /// to take place. The mutable borrow statically guarantees no locks exist. + /// + /// # Examples + /// + /// ``` + /// use happylock::{RwLock, ThreadKey}; + /// + /// let key = ThreadKey::get().unwrap(); + /// let mut lock = RwLock::new(0); + /// *lock.get_mut() = 10; + /// assert_eq!(*lock.read(key), 10); + /// ``` pub fn get_mut(&mut self) -> &mut T { self.data.get_mut() } |
