This is unreleased documentation for Yew Next version.
For up-to-date documentation, see the latest version on docs.rs.
yew::platform::pinned

Struct RwLock

pub struct RwLock<T>
where T: ?Sized,
{ /* private fields */ }
Expand description

An asynchronous reader-writer lock.

This type of lock allows a number of readers or at most one writer at any point in time. The write portion of this lock typically allows modification of the underlying data (exclusive access) and the read portion of this lock typically allows for read-only access (shared access).

The acquisition order of this lock is not guaranteed and depending on the runtime’s implementation and preference of any used polling combinators.

§Examples

let lock = RwLock::new(5);

// many reader locks can be held at once
{
    let r1 = lock.read().await;
    let r2 = lock.read().await;
    assert_eq!(*r1, 5);
    assert_eq!(*r2, 5);
} // read locks are dropped at this point

// only one write lock may be held, however
{
    let mut w = lock.write().await;
    *w += 1;
    assert_eq!(*w, 6);
} // write lock is dropped here

Implementations§

§

impl<T> RwLock<T>

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

Creates a new RwLock containing value T

pub fn into_inner(self) -> T

Consumes the lock, returning the underlying data.

§

impl<T> RwLock<T>
where T: ?Sized,

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

Attempts to acquire this RwLock with shared read access.

If the access couldn’t be acquired immediately, returns TryLockError. Otherwise, an RAII guard is returned which will release read access when dropped.

This function does not block.

This function does not provide any guarantees with respect to the ordering of whether contentious readers or writers will acquire the lock first.

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

Attempts to lock this RwLock with exclusive write access.

If the lock could not be acquired immediately, returns TryLockError. Otherwise, an RAII guard is returned which will release the lock when it is dropped.

This function does not block.

This function does not provide any guarantees with respect to the ordering of whether contentious readers or writers will acquire the lock first.

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

Locks the current RwLock with shared read access, causing the current task to yield until the lock has been acquired.

This method does not provide any guarantees with respect to the ordering of whether contentious readers or writers will acquire the lock first.

Returns an RAII guard which will release this task’s shared access once it is dropped.

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

Locks the current RwLock with exclusive write access, causing the current task to yield until the lock has been acquired.

This method does not provide any guarantees with respect to the ordering of whether contentious readers or writers will acquire the lock first.

Returns an RAII guard which will drop the write access once it is dropped.

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

Returns a mutable reference to the underlying data.

This call borrows RwLock mutably (at compile-time) so there is no need for dynamic checks.

Trait Implementations§

§

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

§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for RwLock<T>

§

impl<T> !RefUnwindSafe for RwLock<T>

§

impl<T> !Send for RwLock<T>

§

impl<T> !Sync for RwLock<T>

§

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.

§

impl<T> Instrument for T

§

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

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

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 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> IntoPropValue<Option<T>> for T

Source§

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
Source§

impl<T> IntoPropValue<T> for T

Source§

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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