From 84ebd3cf9be21bba8eb6c4d214c868e66965b69a Mon Sep 17 00:00:00 2001 From: Mica White Date: Mon, 11 Mar 2024 17:17:31 -0400 Subject: Add couple more docs --- src/rwlock/rwlock.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src') 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 AsMut for RwLock { } impl RwLock { + /// 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 RwLock { + /// 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() } -- cgit v1.2.3