pub struct Shared<T: ?Sized>(/* private fields */);Expand description
A wrapper around a resource possibly shared with SharedReadLocks and
WeakReadLocks, but no other Shareds.
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
SharedReadLocks.
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, Shareds
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 SharedReadLocks.
Sourcepub fn weak_count(this: &Self) -> usize
pub fn weak_count(this: &Self) -> usize
Gets the number of associated WeakReadLocks.