pub struct Shared<T>(/* private fields */);lite only.Expand description
A wrapper around a resource possibly shared with SharedReadLocks, 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.
Sourcepub async fn lock(this: &mut Self) -> SharedWriteGuard<'_, T>
pub async fn lock(this: &mut Self) -> SharedWriteGuard<'_, T>
Lock this Shared to be able to mutate it, causing the current task to
yield until the lock has been acquired.
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.