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 WeakReadLocks.
Implementations§
Sourcepub async fn lock(&self) -> SharedReadGuard<'_, T>
pub async fn lock(&self) -> SharedReadGuard<'_, T>
Lock this SharedReadLock, causing the current task to yield until the
lock has been acquired.
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, returns TryLockError.
Sourcepub async fn lock_owned(self) -> OwnedSharedReadGuard<T>
pub async fn lock_owned(self) -> OwnedSharedReadGuard<T>
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 Shareds for the same inner value
alive at the same time, which would violate Shareds 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
Shareds invariant of being the only reference that is able to
mutate the inner value.