Skip to main content

AccessCell

Struct AccessCell 

Source
pub struct AccessCell<T> { /* private fields */ }
Expand description

A cell holding a value of type T with re-entrant mutable access.

The first caller of access runs immediately; any further calls to access from within that closure (or its queue) are enqueued and executed in order after the current work completes.

Thread-safe: safe to share across threads and use from multiple threads.

Implementations§

Source§

impl<T> AccessCell<T>

Source

pub fn new(value: T) -> Self

Creates a new AccessCell wrapping value.

Source

pub fn access(&self, f: impl FnOnce(&mut T) + Send + 'static)

Runs f with exclusive mutable access to the inner value.

If called while another access closure is running (re-entrant or from another thread), f is queued and run after the current closure and any other queued closures finish.

The closure must be Send so it can be moved into the queue when called from another thread.

Source

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

Returns an immutable reference to the inner value.

Blocks if an access closure is currently running. Safe to call from any thread.

Trait Implementations§

Source§

impl<T: Send> Send for AccessCell<T>

Source§

impl<T: Send> Sync for AccessCell<T>

Auto Trait Implementations§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.