Struct readlock::SharedReadLock
source · 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.
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)