pub struct TransparentObserverMutableSnapshot { /* private fields */ }Expand description
A transparent mutable snapshot that allows observer replacement.
This snapshot type is optimized for cases where observers need to be temporarily added or removed without creating a new snapshot structure.
§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 TransparentObserverMutableSnapshot
impl TransparentObserverMutableSnapshot
Sourcepub fn new(
id: SnapshotId,
invalid: SnapshotIdSet,
read_observer: Option<ReadObserver>,
write_observer: Option<WriteObserver>,
parent: Option<Weak<TransparentObserverMutableSnapshot>>,
) -> Rc<Self>
pub fn new( id: SnapshotId, invalid: SnapshotIdSet, read_observer: Option<ReadObserver>, write_observer: Option<WriteObserver>, parent: Option<Weak<TransparentObserverMutableSnapshot>>, ) -> Rc<Self>
Creates a transparent mutable snapshot with the given id and invalid set. The observers are
called for reads and writes inside it and can be replaced later. parent is the snapshot it
was taken from, if that snapshot is still alive.
Sourcepub fn set_read_observer(&self, observer: Option<ReadObserver>)
pub fn set_read_observer(&self, observer: Option<ReadObserver>)
Set the read observer (only allowed if reusable).
Sourcepub fn set_write_observer(&self, observer: Option<WriteObserver>)
pub fn set_write_observer(&self, observer: Option<WriteObserver>)
Set the write observer (only allowed if reusable).
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_transparent_mutable(self: &Rc<Self>) -> Rc<Self>
pub fn root_transparent_mutable(self: &Rc<Self>) -> Rc<Self>
Returns the outermost parent that is still alive, or this snapshot when it has none.
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. If
this snapshot is already current, f runs directly. 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 dispose(&self)
pub fn dispose(&self)
Releases the snapshot. Does nothing if it was already disposed or if 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.
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
Marks the snapshot as applied. Returns Failure if it was already applied or disposed.
Sourcepub fn take_nested_mutable_snapshot(
&self,
read_observer: Option<ReadObserver>,
write_observer: Option<WriteObserver>,
) -> Rc<TransparentObserverMutableSnapshot>
pub fn take_nested_mutable_snapshot( &self, read_observer: Option<ReadObserver>, write_observer: Option<WriteObserver>, ) -> Rc<TransparentObserverMutableSnapshot>
Takes a transparent mutable snapshot nested in this one. Reads and writes inside it call both the given observers and this snapshot’s own observers.