From 9eec9ab94bbe5c9fbd52d5bbf393fe1ddcc6fc26 Mon Sep 17 00:00:00 2001 From: Mica White Date: Thu, 26 Dec 2024 12:06:47 -0500 Subject: Documentation --- src/rwlock/rwlock.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/rwlock/rwlock.rs') diff --git a/src/rwlock/rwlock.rs b/src/rwlock/rwlock.rs index 6432128..a249675 100644 --- a/src/rwlock/rwlock.rs +++ b/src/rwlock/rwlock.rs @@ -277,10 +277,19 @@ impl RwLock { /// Attempts to acquire this `RwLock` with shared read access without /// blocking. /// - /// If the access could not be granted at this time, then `None` is + /// If the access could not be granted at this time, then `Err` is /// returned. Otherwise, an RAII guard is returned which will release the /// shared access when it is dropped. /// + /// This function does not provide any guarantees with respect to the + /// ordering of whether contentious readers or writers will acquire the + /// lock first. + /// + /// # Errors + /// + /// If the `RwLock` could not be acquired because it was already locked + /// exclusively, then an error will be returned containing the given key. + /// /// # Examples /// /// ``` @@ -351,8 +360,10 @@ impl RwLock { /// let key = ThreadKey::get().unwrap(); /// let lock = RwLock::new(1); /// - /// let mut n = lock.write(key); - /// *n += 2; + /// match lock.try_write(key) { + /// Ok(n) => assert_eq!(*n, 1), + /// Err(_) => unreachable!(), + /// }; /// ``` /// /// [`ThreadKey`]: `crate::ThreadKey` @@ -378,6 +389,11 @@ impl RwLock { /// ordering of whether contentious readers or writers will acquire the /// lock first. /// + /// # Errors + /// + /// If the `RwLock` could not be acquired because it was already locked, + /// then an error will be returned containing the given key. + /// /// # Examples /// /// ``` -- cgit v1.2.3