pub struct SharedReadLock<T: ?Sized>(/* private fields */);
Expand description
A read-only reference to a resource possibly shared with up to one
Shared
and many WeakReadLock
s.
Implementations§
Sourcepub fn lock(&self) -> SharedReadGuard<'_, T>
pub fn lock(&self) -> SharedReadGuard<'_, T>
Lock this SharedReadLock
, blocking the current thread until the
operation succeeds.
Sourcepub fn try_lock(&self) -> TryLockResult<SharedReadGuard<'_, T>>
pub fn try_lock(&self) -> TryLockResult<SharedReadGuard<'_, T>>
Try to lock this SharedReadLock
.
If the value is currently locked for writing through the corresponding
Shared
instance or the lock was poisoned, returns TryLockError
.
Sourcepub fn downgrade(&self) -> WeakReadLock<T>
pub fn downgrade(&self) -> WeakReadLock<T>
Create a new WeakReadLock
pointer to this allocation.
Sourcepub fn try_upgrade(self) -> Result<Shared<T>, Self>
pub fn try_upgrade(self) -> Result<Shared<T>, Self>
Upgrade a SharedReadLock
to Shared
.
This only return Ok(_)
if there are no other references (including a
Shared
, or weak references) to the inner value, since otherwise it
would be possible to have multiple Shared
s for the same inner value
alive at the same time, which would violate Shared
s invariant of
being the only reference that is able to mutate the inner value.
Sourcepub fn from_inner(rwlock: Arc<RwLock<T>>) -> Self
pub fn from_inner(rwlock: Arc<RwLock<T>>) -> Self
Create a SharedReadLock
from its internal representation,
Arc<RwLock<T>>
.
You can use this to create a SharedReadLock
from a shared RwLock
without ever using Shared
, if you want to expose an API where there is
a value that can be written only from inside one module or crate, but
outside users should be allowed to obtain a reusable lock for reading
the inner value.
Sourcepub fn try_into_inner(self) -> Result<Arc<RwLock<T>>, Self>
pub fn try_into_inner(self) -> Result<Arc<RwLock<T>>, Self>
Attempt to turn this SharedReadLock
into its internal representation,
Arc<RwLock<T>>
.
This returns Ok(_)
only if there are no further references (including
a Shared
, or weak references) to the inner value, since otherwise
it would be possible to have a Shared
and an Arc<RwLock<T>>
for
the same inner value alive at the same time, which would violate
Shared
s invariant of being the only reference that is able to
mutate the inner value.