readlock

Crates.ioreadlock
lib.rsreadlock
version0.1.8
sourcesrc
created_at2023-02-18 23:39:50.283685
updated_at2024-07-13 20:45:31.77486
descriptionA weird alternative to Arc>
homepage
repositoryhttps://github.com/jplatte/readlock
max_upload_size
id788551
size19,918
Jonas Platte (jplatte)

documentation

README

readlock

(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.
Commit count: 32

cargo fmt