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.

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) + 'static)

Runs f with exclusive mutable access to the inner value.

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

Source

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

Returns a mutable reference to the inner value.

§Safety

Only call this while you are inside an access closure (or while draining the queue). Otherwise you may create aliasing mutable references.

Source

pub fn access_ref(&self) -> &T

Returns an immutable reference to the inner value.

Safe to call at any time; no closure is running when you use this for read-only access.

Auto Trait Implementations§

§

impl<T> !Freeze for AccessCell<T>

§

impl<T> !RefUnwindSafe for AccessCell<T>

§

impl<T> !Send for AccessCell<T>

§

impl<T> !Sync for AccessCell<T>

§

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

§

impl<T> UnwindSafe for AccessCell<T>
where T: UnwindSafe,

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.