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:
- The
stateparameter must be compatible with the currentSimulationInfoinstance. Implementations of this trait may assume that the providedstateis compatible. - When calling
callorrevert, thestatemust be callable or revertable for the specifiedevent.
Violating these invariants may lead to undefined behavior or incorrect simulation results.
Required Associated Types§
Sourcetype StateLoadingError
type StateLoadingError
The error type returned when loading the simulation state fails.
Sourcetype AccessData: ?Sized
type AccessData: ?Sized
The type used to access the current state.
Sourcetype EventContainer<'a>: Iterator<Item = Self::Event>
where
Self: 'a
type EventContainer<'a>: Iterator<Item = Self::Event> where Self: 'a
The type of container used to access the available events.
Required Methods§
Sourcefn default_state(&self) -> Self::State
fn default_state(&self) -> Self::State
Creates a new default state compatible with this SimulationInfo instance.
Sourcefn load_state(
&self,
data: Self::LoadData,
) -> Result<Self::State, Self::StateLoadingError>
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.
Sourceunsafe fn clone_state(&self, state: &Self::State) -> Self::State
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.
Sourceunsafe fn data<'a>(&self, state: &'a Self::State) -> &'a Self::AccessData
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.
Sourcefn callables(state: &Self::State) -> Self::EventContainer<'_>
fn callables(state: &Self::State) -> Self::EventContainer<'_>
Returns the events that can be called for the provided state.
Sourcefn revertables(state: &Self::State) -> Self::EventContainer<'_>
fn revertables(state: &Self::State) -> Self::EventContainer<'_>
Returns the events that can be reverted for the provided state.
Sourcefn callable(state: &Self::State, event: Self::Event) -> bool
fn callable(state: &Self::State, event: Self::Event) -> bool
Checks if the provided event can be called for the given state.
Sourcefn revertable(state: &Self::State, event: Self::Event) -> bool
fn revertable(state: &Self::State, event: Self::Event) -> bool
Checks if the provided event can be reverted for the given state.
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.