RWLock

Struct RWLock 

Source
#[repr(C, align(16))]
pub struct RWLock<T: ?Sized> { /* private fields */ }
Expand description

An exclusive access lock around the given data

Implementations§

Source§

impl<T> RWLock<T>

Source

pub const fn new(value: T) -> Self

Create a new data access guarding lock.

Source§

impl<T: ?Sized> RWLock<T>

Source

pub fn try_write(&self) -> Option<WriteLockGuard<'_, T>>

Try to provide a Writelock for mutual exclusive access. Returns None if the lock fails or Some(WriteLockGuard). The actual data, the WriteLockGuard wraps could be conviniently accessed by dereferencing it.

Source

pub fn write(&self) -> WriteLockGuard<'_, T>

Provide a WriteLock for mutual exclusive access. This blocks until the data could be successfully locked. This also implies that there is no concurrent ReadLockGuard existing. The locked data will be returned as WriteLockGuard. Simply derefrencing this allows access to the contained data value.

Source

pub fn try_read(&self) -> Option<ReadLockGuard<'_, T>>

Provide a ReadLock to the wrapped data. This call blocks until the recource is available. There can be as many concurrent ReadLockGuards being handed out if there is no WriteLockGuard to the same resource already existing.

Source

pub fn read(&self) -> ReadLockGuard<'_, T>

Provide a ReadLock to the wrapped data. This call blocks until the recource is available. There can be as many concurrent ReadLockGuards being handed out if there is no WriteLockGuard to the same resource already existing.

Source

pub unsafe fn as_ref_unchecked(&self) -> &T

Provide an immutable borrow to the data secured by the RWLock.

§Safety

This is only safe if it is guarantied that there is exactly only one call to this function or any other accessor of the RWLock until the returned borrow goes out of scope.

Source

pub fn into_inner(self) -> T
where T: Sized,

Consume the Mutex and return the inner value

Trait Implementations§

Source§

impl<T> Debug for RWLock<T>
where T: Debug + ?Sized,

Source§

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

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

impl<T: ?Sized + Send> Sync for RWLock<T>

The RWLock is always Sync, to make it Send as well it need to be wrapped into an Arc.

Auto Trait Implementations§

§

impl<T> !Freeze for RWLock<T>

§

impl<T> !RefUnwindSafe for RWLock<T>

§

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

§

impl<T> Unpin for RWLock<T>
where T: Unpin + ?Sized,

§

impl<T> UnwindSafe for RWLock<T>
where T: UnwindSafe + ?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<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.