pub struct NestedMutableSnapshot { /* private fields */ }Expand description
A nested mutable snapshot.
This is a mutable snapshot that has a parent. Changes made in this
snapshot are applied to the parent when apply() is called, not
to the global snapshot.
§Thread Safety
Contains Cell<T> and RefCell<T> which are 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 NestedMutableSnapshot
impl NestedMutableSnapshot
Sourcepub fn new(
id: SnapshotId,
invalid: SnapshotIdSet,
read_observer: Option<ReadObserver>,
write_observer: Option<WriteObserver>,
parent: Weak<MutableSnapshot>,
base_parent_id: SnapshotId,
) -> Rc<Self>
pub fn new( id: SnapshotId, invalid: SnapshotIdSet, read_observer: Option<ReadObserver>, write_observer: Option<WriteObserver>, parent: Weak<MutableSnapshot>, base_parent_id: SnapshotId, ) -> Rc<Self>
Creates a nested mutable snapshot with the given id and invalid set. parent receives the
writes on apply. base_parent_id is the id of the parent when this snapshot was taken.
Sourcepub fn snapshot_id(&self) -> SnapshotId
pub fn snapshot_id(&self) -> SnapshotId
Returns the id of this snapshot. Ids grow with every snapshot taken.
Sourcepub fn invalid(&self) -> SnapshotIdSet
pub fn invalid(&self) -> SnapshotIdSet
Returns the ids of snapshots whose writes this snapshot does not see.
Sourcepub fn root_mutable(&self) -> Rc<MutableSnapshot>
pub fn root_mutable(&self) -> Rc<MutableSnapshot>
Returns the root mutable snapshot above this one. If the root is gone, returns a new root snapshot built from this snapshot’s id, invalid set and observers.
Sourcepub fn enter<T>(self: &Rc<Self>, f: impl FnOnce() -> T) -> T
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.
Sourcepub fn take_nested_snapshot(
&self,
read_observer: Option<ReadObserver>,
) -> Rc<ReadonlySnapshot>
pub fn take_nested_snapshot( &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.
Sourcepub fn has_pending_changes(&self) -> bool
pub fn has_pending_changes(&self) -> bool
Returns true when this snapshot recorded writes that were not applied yet.
Sourcepub fn pending_children(&self) -> Vec<SnapshotId> ⓘ
pub fn pending_children(&self) -> Vec<SnapshotId> ⓘ
Returns the ids of nested mutable snapshots taken from this snapshot and not yet disposed.
Sourcepub fn has_pending_children(&self) -> bool
pub fn has_pending_children(&self) -> bool
Returns true when a nested mutable snapshot taken from this snapshot is still open.
Sourcepub fn dispose(&self)
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.
Sourcepub fn record_read(&self, state: &dyn StateObject)
pub fn record_read(&self, state: &dyn StateObject)
Calls the read observer, if any, with state.
Sourcepub fn record_write(&self, state: Rc<dyn StateObject>)
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.
Sourcepub fn is_disposed(&self) -> bool
pub fn is_disposed(&self) -> bool
Returns true once the snapshot was disposed.
Sourcepub fn apply(&self) -> SnapshotApplyResult
pub fn apply(&self) -> SnapshotApplyResult
Moves the writes of this snapshot into its parent. Returns Failure if the snapshot was
already applied or disposed, if the parent is gone, or if the parent wrote one of the same
state objects.
Sourcepub fn take_nested_mutable_snapshot(
self: &Rc<Self>,
read_observer: Option<ReadObserver>,
write_observer: Option<WriteObserver>,
) -> Rc<NestedMutableSnapshot>
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.