pub struct Shared<T: ?Sized>(/* private fields */);
Expand description
A wrapper around a resource possibly shared with SharedReadLock
s and
WeakReadLock
s, but no other Shared
s.
Implementations§
sourcepub fn unwrap(this: Self) -> Result<T, Self>
pub fn unwrap(this: Self) -> Result<T, Self>
Returns the inner value, if the Shared
has no associated
SharedReadLock
s.
Otherwise, an Err
is returned with the same Shared
that was passed
in.
This will succeed even if there are outstanding weak references.
§Panics
This function will panic if the lock around the inner value is poisoned.
sourcepub fn get(this: &Self) -> &T
pub fn get(this: &Self) -> &T
Get a reference to the inner value.
Usually, you don’t need to call this function since Shared<T>
implements Deref
. Use this if you want to pass the inner value to a
generic function where the compiler can’t infer that you want to have
the Shared
dereferenced otherwise.
§Panics
This function will panic if the lock around the inner value is poisoned.
sourcepub fn try_get(this: &Self) -> LockResult<&T>
pub fn try_get(this: &Self) -> LockResult<&T>
Try to get a reference to the inner value, returning an error if the lock around it is poisoned.
sourcepub fn lock(this: &mut Self) -> SharedWriteGuard<'_, T>
pub fn lock(this: &mut Self) -> SharedWriteGuard<'_, T>
Lock this Shared
to be able to mutate it, blocking the current thread
until the operation succeeds.
sourcepub fn get_read_lock(this: &Self) -> SharedReadLock<T>
pub fn get_read_lock(this: &Self) -> SharedReadLock<T>
Get a SharedReadLock
for accessing the same resource read-only from
elsewhere.
sourcepub fn try_from_inner(rwlock: Arc<RwLock<T>>) -> Result<Self, Arc<RwLock<T>>>
pub fn try_from_inner(rwlock: Arc<RwLock<T>>) -> Result<Self, Arc<RwLock<T>>>
Attempt to create a Shared
from its internal representation,
Arc<RwLock<T>>
.
This returns Ok(_)
only if there are no further references (including
weak references) to the inner RwLock
since otherwise, Shared
s
invariant of being the only instance that can mutate the inner value
would be broken.
sourcepub fn into_inner(this: Self) -> Arc<RwLock<T>>
pub fn into_inner(this: Self) -> Arc<RwLock<T>>
Turns this Shared
into its internal representation, Arc<RwLock<T>>
.
sourcepub fn read_count(this: &Self) -> usize
pub fn read_count(this: &Self) -> usize
Gets the number of associated SharedReadLock
s.
sourcepub fn weak_count(this: &Self) -> usize
pub fn weak_count(this: &Self) -> usize
Gets the number of associated WeakReadLock
s.