SimulationInfo

Trait SimulationInfo 

Source
pub trait SimulationInfo {
    type State;
    type StateLoadingError;
    type AccessData: ?Sized;
    type LoadData;
    type Event: Copy + Ord;
    type EventContainer<'a>: Iterator<Item = Self::Event>
       where Self: 'a;

    // Required methods
    fn default_state(&self) -> Self::State;
    fn load_state(
        &self,
        data: Self::LoadData,
    ) -> Result<Self::State, Self::StateLoadingError>;
    unsafe fn clone_state(&self, state: &Self::State) -> Self::State;
    unsafe fn data<'a>(&self, state: &'a Self::State) -> &'a Self::AccessData;
    fn callables(state: &Self::State) -> Self::EventContainer<'_>;
    fn revertables(state: &Self::State) -> Self::EventContainer<'_>;
    fn callable(state: &Self::State, event: Self::Event) -> bool;
    fn revertable(state: &Self::State, event: Self::Event) -> bool;
    unsafe fn call(&self, state: &mut Self::State, event: Self::Event);
    unsafe fn revert(&self, state: &mut Self::State, event: Self::Event);
}
Expand description

The SimulationInfo trait provides an interface for interacting with a simulation.

§Safety

This trait contains methods marked as unsafe that require careful usage. The following invariants must be upheld when calling these methods:

  1. The state parameter must be compatible with the current SimulationInfo instance. Implementations of this trait may assume that the provided state is compatible.
  2. When calling call or revert, the state must be callable or revertable for the specified event.

Violating these invariants may lead to undefined behavior or incorrect simulation results.

Required Associated Types§

Source

type State

The type of the simulation state.

Source

type StateLoadingError

The error type returned when loading the simulation state fails.

Source

type AccessData: ?Sized

The type used to access the current state.

Source

type LoadData

The type of data used to load the simulation state.

Source

type Event: Copy + Ord

The type of events that can be called or reverted in the simulation.

Source

type EventContainer<'a>: Iterator<Item = Self::Event> where Self: 'a

The type of container used to access the available events.

Required Methods§

Source

fn default_state(&self) -> Self::State

Creates a new default state compatible with this SimulationInfo instance.

Source

fn load_state( &self, data: Self::LoadData, ) -> Result<Self::State, Self::StateLoadingError>

Loads a state from the provided data, returning a Result with the loaded state or an error.

Source

unsafe fn clone_state(&self, state: &Self::State) -> Self::State

Clones the provided state, assuming it is compatible with this SimulationInfo instance.

§Safety

The caller must ensure that the provided state is compatible with this SimulationInfo instance.

Source

unsafe fn data<'a>(&self, state: &'a Self::State) -> &'a Self::AccessData

Returns a reference to the data which repsesents the state.

§Safety

The caller must ensure that the provided state is compatible with this SimulationInfo instance.

Source

fn callables(state: &Self::State) -> Self::EventContainer<'_>

Returns the events that can be called for the provided state.

Source

fn revertables(state: &Self::State) -> Self::EventContainer<'_>

Returns the events that can be reverted for the provided state.

Source

fn callable(state: &Self::State, event: Self::Event) -> bool

Checks if the provided event can be called for the given state.

Source

fn revertable(state: &Self::State, event: Self::Event) -> bool

Checks if the provided event can be reverted for the given state.

Source

unsafe fn call(&self, state: &mut Self::State, event: Self::Event)

Calls the provided event on the given mutable state.

§Safety

The caller must ensure that the provided state is compatible with this SimulationInfo instance and that the state is callable for the specified event.

Source

unsafe fn revert(&self, state: &mut Self::State, event: Self::Event)

Reverts the provided event on the given mutable state.

§Safety

The caller must ensure that the provided state is compatible with this SimulationInfo instance and that the state is revertable for the specified event.

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§