7 releases

0.1.5 Mar 28, 2023
0.1.4 Mar 16, 2023
0.1.1 Feb 23, 2023
0.0.1 Feb 18, 2023

#208 in Concurrency

Download history 200/week @ 2023-02-17 762/week @ 2023-02-24 2520/week @ 2023-03-03 3055/week @ 2023-03-10 2009/week @ 2023-03-17 2306/week @ 2023-03-24 1519/week @ 2023-03-31 944/week @ 2023-04-07 1615/week @ 2023-04-14 2608/week @ 2023-04-21 2546/week @ 2023-04-28 3291/week @ 2023-05-05

10,337 downloads per month
Used in eyeball

MPL-2.0 license

164 lines


(Shared) Read-Only Lock: A thing that can be useful when you don't really want shared mutability, you just want to mutate a value from one place and read it from many others.

This library provides three types:

  • Shared<T>: similar to Arc<RwLock<T>>, but you can only create SharedReadLock<T>s and WeakReadLock<T>s from it that share access to the same inner value, not further Shared<T>s. Also, acquiring a write lock requires unique ownership / borrowing (&mut self). However: Reading requires no locking because mutably borrowing the Shared means that no other thread can be mutating the value at the same time (all other reference to the value are read-only).
  • SharedReadLock<T>: like a Arc<RwLock<T>> that is only ever used for reading. Can be downgraded to WeakReadLock.
  • WeakReadLock<T>: like a Weak<RwLock<T>>. That is, it references the same memory, but if the original Shared and any derived SharedReadLocks to that value are dropped, it will be deallocated regardless of any WeakReadLocks. Must be upgraded into SharedReadLock to access the inner value.

No runtime deps