Simulation

Struct Simulation 

Source
pub struct Simulation<S> { /* private fields */ }
Expand description

The overarching simulation state. Contains the scenario being modelled, the current state of the simulation, as well as a cursor pointing to the next event in the timeline that is scheduled to be applied.

Implementations§

Source§

impl<S> Simulation<S>

Methods for affecting control over the simulation. Most of these emit a broad SimulationError if something goes wrong, with a specific error variant for each envisaged error type. Not all methods use every available SimulationError variant.

Check the documentation of each method for the specific variants that are returned by that method, bearing in mind that the variants that a method is allowed to return may change over time.

Source

pub fn step(&mut self) -> Result<(), SimulationError<S>>

Evaluates the next event in the timeline, applying it to the current state to transition to the next state.

§Errors

SimulationError if an error occurs. Expected variants:

Source

pub fn reset(&mut self)
where S: Clone,

Resets the simulation, reinitialising the current state from the initial state specified in the simulation scenario, and resetting the cursor to location 0.

Source

pub fn jump(&mut self, location: usize) -> Result<(), SimulationError<S>>
where S: Clone,

Jumps to a specified location in the timeline and evaluates the event at that location.

§Errors

SimulationError if an error occurs. Expected variants:

Source

pub fn run(&mut self) -> Result<(), SimulationError<S>>

Evaluates the remaining events in the timeline.

§Errors

SimulationError if an error occurs. Expected variants:

Source

pub fn push_event( &mut self, event: Box<dyn Event<State = S>>, ) -> Result<(), SimulationError<S>>

Appends an event to the timeline at the current cursor location, assuming that there are no events at and beyond that location.

§Errors

SimulationError if an error occurs. Expected variants:

Source

pub fn truncate(&mut self)

Truncates the timeline at the current cursor location, dropping all events at and beyond this point.

Source

pub fn scenario(&self) -> &Scenario<S>

A reference to the underlying scenario.

Source

pub fn set_scenario(&mut self, scenario: Scenario<S>)
where S: Clone,

Assigns a new scenario, resetting the simulation in the process.

Source

pub fn current_state(&self) -> &S

A reference to the current simulation state.

Source

pub fn cursor(&self) -> usize

The current cursor location.

Trait Implementations§

Source§

impl<S: Debug> Debug for Simulation<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: Default + Clone> Default for Simulation<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<S: Clone> From<Scenario<S>> for Simulation<S>

Source§

fn from(scenario: Scenario<S>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<S> Freeze for Simulation<S>
where S: Freeze,

§

impl<S> !RefUnwindSafe for Simulation<S>

§

impl<S> !Send for Simulation<S>

§

impl<S> !Sync for Simulation<S>

§

impl<S> Unpin for Simulation<S>
where S: Unpin,

§

impl<S> !UnwindSafe for Simulation<S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.