Skip to main content

MutableSnapshot

Struct MutableSnapshot 

Source
pub struct MutableSnapshot { /* private fields */ }
Expand description

A mutable snapshot that allows isolated state changes.

Changes made in a mutable snapshot are isolated from other snapshots until apply() is called, at which point they become visible atomically. This is a root mutable snapshot (not nested).

§Thread Safety

Contains Cell<T> which is not Send/Sync. This is safe because snapshots are stored in thread-local storage and never shared across threads. The Rc is used for cheap cloning within a single thread, not for cross-thread sharing.

Implementations§

Source§

impl MutableSnapshot

Source

pub fn new( id: SnapshotId, invalid: SnapshotIdSet, read_observer: Option<ReadObserver>, write_observer: Option<WriteObserver>, base_parent_id: SnapshotId, ) -> Rc<Self>

Create a new root mutable snapshot.

Source

pub fn snapshot_id(&self) -> SnapshotId

Returns the id of this snapshot. Ids grow with every snapshot taken.

Source

pub fn invalid(&self) -> SnapshotIdSet

Returns the ids of snapshots whose writes this snapshot does not see.

Source

pub fn read_only(&self) -> bool

Returns false: this snapshot accepts writes.

Source

pub fn root_mutable(self: &Rc<Self>) -> Rc<Self>

Returns this snapshot, which is its own root.

Source

pub fn enter<T>(self: &Rc<Self>, f: impl FnOnce() -> T) -> T

Runs f with this snapshot as the current snapshot of the thread and returns its result. The previous current snapshot is restored when f returns.

Source

pub fn take_nested_snapshot( self: &Rc<Self>, read_observer: Option<ReadObserver>, ) -> Rc<ReadonlySnapshot>

Takes a read-only snapshot of this snapshot’s view of state. Reads inside the new snapshot call both read_observer and this snapshot’s own read observer. Panics if this snapshot was applied or disposed.

Source

pub fn has_pending_changes(&self) -> bool

Returns true when this snapshot recorded writes that were not applied yet.

Source

pub fn pending_children(&self) -> Vec<SnapshotId> ⓘ

Returns the ids of nested mutable snapshots taken from this snapshot and not yet disposed.

Source

pub fn has_pending_children(&self) -> bool

Returns true when a nested mutable snapshot taken from this snapshot is still open.

Source

pub fn dispose(&self)

Discards the writes that were not applied and releases the snapshot. Does nothing while nested snapshots taken from it are still open.

Source

pub fn record_read(&self, state: &dyn StateObject)

Calls the read observer, if any, with state.

Source

pub fn record_write(&self, state: Rc<dyn StateObject>)

Records state as written in this snapshot. The write observer, if any, is called the first time a state object is recorded. Panics if the snapshot was applied or disposed.

Source

pub fn is_disposed(&self) -> bool

Returns true once the snapshot was disposed.

Source

pub fn apply(&self) -> SnapshotApplyResult

Makes the writes of this snapshot visible to the global state. Returns Failure if the snapshot was already applied or disposed, or if a state object it wrote changed in the global state in a way that cannot be merged. After a successful apply with writes, the apply observers are called.

Source

pub fn take_nested_mutable_snapshot( self: &Rc<Self>, read_observer: Option<ReadObserver>, write_observer: Option<WriteObserver>, ) -> Rc<NestedMutableSnapshot>

Takes a mutable snapshot nested in this one. Its apply moves the writes into this snapshot. Panics if this snapshot was applied or disposed.

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.