rustc_data_structures::undo_log

Trait Snapshots

Source
pub trait Snapshots<T>: UndoLogs<T> {
    type Snapshot;

    // Required methods
    fn actions_since_snapshot(&self, snapshot: &Self::Snapshot) -> &[T];
    fn start_snapshot(&mut self) -> Self::Snapshot;
    fn rollback_to<R>(
        &mut self,
        storage: impl FnOnce() -> R,
        snapshot: Self::Snapshot,
    )
       where R: Rollback<T>;
    fn commit(&mut self, snapshot: Self::Snapshot);

    // Provided method
    fn has_changes(&self, snapshot: &Self::Snapshot) -> bool { ... }
}
Expand description

A trait which extends UndoLogs to allow snapshots to be done at specific points. Each snapshot can then be used to rollback any changes to an underlying data structures if they were not desirable.

Each snapshot must be consumed linearly with either rollback_to or commit.

Required Associated Types§

Required Methods§

Source

fn actions_since_snapshot(&self, snapshot: &Self::Snapshot) -> &[T]

Returns the slice of actions that were taken since the snapshot began.

Source

fn start_snapshot(&mut self) -> Self::Snapshot

Starts a new snapshot. That snapshot must eventually either be committed via a call to commit or rollback via rollback_to. Snapshots can be nested (i.e., you can start a snapshot whilst another snapshot is in progress) but you must then commit or rollback the inner snapshot before attempting to commit or rollback the outer snapshot.

Source

fn rollback_to<R>( &mut self, storage: impl FnOnce() -> R, snapshot: Self::Snapshot, )
where R: Rollback<T>,

Rollback (undo) the changes made to storage since the snapshot.

Source

fn commit(&mut self, snapshot: Self::Snapshot)

Commit: keep the changes that have been made since the snapshot began

Provided Methods§

Source

fn has_changes(&self, snapshot: &Self::Snapshot) -> bool

Returns true if self has made any changes since snapshot started.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T, U> Snapshots<T> for &mut U
where U: Snapshots<T>,

Source§

type Snapshot = <U as Snapshots<T>>::Snapshot

Source§

fn has_changes(&self, snapshot: &<U as Snapshots<T>>::Snapshot) -> bool

Source§

fn actions_since_snapshot( &self, snapshot: &<U as Snapshots<T>>::Snapshot, ) -> &[T]

Source§

fn start_snapshot(&mut self) -> <U as Snapshots<T>>::Snapshot

Source§

fn rollback_to<R>( &mut self, storage: impl FnOnce() -> R, snapshot: <U as Snapshots<T>>::Snapshot, )
where R: Rollback<T>,

Source§

fn commit(&mut self, snapshot: <U as Snapshots<T>>::Snapshot)

Implementors§