Trait StateChangeTracker

Source
pub trait StateChangeTracker<ET: EngineTypes>: State<ET> {
    // Required method
    fn stack(&mut self) -> &mut StateStack<ET>;

    // Provided method
    fn change_field<F: FnOnce(&mut Self, bool) -> StateChange<ET>>(
        &mut self,
        globally: bool,
        f: F,
    ) { ... }
}
Expand description

Convenience trait for tracking state changes in a StateStack and rolling them back if necessary at the end of a group.

Required Methods§

Source

fn stack(&mut self) -> &mut StateStack<ET>

Get the current StateStack

Provided Methods§

Source

fn change_field<F: FnOnce(&mut Self, bool) -> StateChange<ET>>( &mut self, globally: bool, f: F, )

Change a field of the state, and add the change to the StateStack. Also takes care of inspecting and considering the current \globaldefs value and passes on the actual computed globally value to the continuation function, which should return the StateChange containg the old value.

For example, on \count5=4, you could call this function like this: self.change_field(false,|slf,g| StateChange::IntRegister(5,std::mem::replace(&mut slf.int_registers[5],4)))

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.

Implementors§