readlock

Struct Shared

Source
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§

Source§

impl<T> Shared<T>

Source

pub fn new(data: T) -> Self

Create a new Shared.

Source

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.

Source§

impl<T: ?Sized> Shared<T>

Source

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.

Source

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.

Source

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.

Source

pub fn get_read_lock(this: &Self) -> SharedReadLock<T>

Get a SharedReadLock for accessing the same resource read-only from elsewhere.

Source

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.

Source

pub fn into_inner(this: Self) -> Arc<RwLock<T>>

Turns this Shared into its internal representation, Arc<RwLock<T>>.

Source

pub fn read_count(this: &Self) -> usize

Gets the number of associated SharedReadLocks.

Source

pub fn weak_count(this: &Self) -> usize

Gets the number of associated WeakReadLocks.

Trait Implementations§

Source§

impl<T: Debug + ?Sized> Debug for Shared<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default> Default for Shared<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: ?Sized> Deref for Shared<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<T> Freeze for Shared<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for Shared<T>
where T: ?Sized,

§

impl<T> Send for Shared<T>
where T: Send + Sync + ?Sized,

§

impl<T> Sync for Shared<T>
where T: Send + Sync + ?Sized,

§

impl<T> Unpin for Shared<T>
where T: ?Sized,

§

impl<T> UnwindSafe for Shared<T>
where T: ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.