pub struct NestedReadonlySnapshot { /* private fields */ }Expand description
A nested read-only snapshot.
This is a read-only snapshot that has a parent snapshot. It inherits the parent’s invalid set and can be disposed independently.
§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 NestedReadonlySnapshot
impl NestedReadonlySnapshot
Sourcepub fn new(
id: SnapshotId,
invalid: SnapshotIdSet,
read_observer: Option<ReadObserver>,
parent: Weak<NestedReadonlySnapshot>,
) -> Rc<Self>
pub fn new( id: SnapshotId, invalid: SnapshotIdSet, read_observer: Option<ReadObserver>, parent: Weak<NestedReadonlySnapshot>, ) -> Rc<Self>
Creates a nested read-only snapshot with the given id and invalid set. read_observer is
called for reads inside it. parent is the snapshot it was taken from, if that snapshot is
still alive.
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_nested_readonly(&self) -> Rc<NestedReadonlySnapshot>
pub fn root_nested_readonly(&self) -> Rc<NestedReadonlySnapshot>
Returns the outermost parent that is still alive, or a copy of this snapshot when it has no live parent.
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<NestedReadonlySnapshot>
pub fn take_nested_snapshot( &self, read_observer: Option<ReadObserver>, ) -> Rc<NestedReadonlySnapshot>
Takes another read-only snapshot with the same 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 false: a read-only snapshot has no writes.
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>)
Always panics: a read-only snapshot rejects writes.
Sourcepub fn is_disposed(&self) -> bool
pub fn is_disposed(&self) -> bool
Returns true once the snapshot was disposed.