Struct loom::sync::RwLock

source ·
pub struct RwLock<T> { /* private fields */ }
Expand description

Mock implementation of std::sync::RwLock

Implementations§

source§

impl<T> RwLock<T>

source

pub fn new(data: T) -> RwLock<T>

Creates a new rwlock in an unlocked state ready for use.

source

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

Locks this rwlock with shared read access, blocking the current thread until it can be acquired.

The calling thread will be blocked until there are no more writers which hold the lock. There may be other readers currently inside the lock when this method returns. This method does not provide any guarantees with respect to the ordering of whether contentious readers or writers will acquire the lock first.

source

pub fn try_read(&self) -> TryLockResult<RwLockReadGuard<'_, T>>

Attempts to acquire this rwlock with shared read access.

If the access could not be granted at this time, then Err is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped.

This function does not block.

source

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

Locks this rwlock with exclusive write access, blocking the current thread until it can be acquired.

This function will not return while other writers or other readers currently have access to the lock.

source

pub fn try_write(&self) -> TryLockResult<RwLockWriteGuard<'_, T>>

Attempts to lock this rwlock with exclusive write access.

If the lock could not be acquired at this time, then Err is returned. Otherwise, an RAII guard is returned which will release the lock when it is dropped.

This function does not block.

source

pub fn get_mut(&mut self) -> LockResult<&mut T>

Returns a mutable reference to the underlying data.

source

pub fn into_inner(self) -> LockResult<T>

Consumes this RwLock, returning the underlying data.

Trait Implementations§

source§

impl<T: Debug> Debug for RwLock<T>

source§

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

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

impl<T: Default> Default for RwLock<T>

source§

fn default() -> Self

Creates a RwLock<T>, with the Default value for T.

source§

impl<T> From<T> for RwLock<T>

source§

fn from(t: T) -> Self

Creates a new rwlock in an unlocked state ready for use. This is equivalent to RwLock::new.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for RwLock<T>

§

impl<T> Send for RwLock<T>where T: Send,

§

impl<T> Sync for RwLock<T>where T: Send + Sync,

§

impl<T> Unpin for RwLock<T>where T: Unpin,

§

impl<T> UnwindSafe for RwLock<T>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more