Skip to main content

SimContext

Struct SimContext 

Source
pub struct SimContext { /* private fields */ }
Expand description

Central simulation context.

Holds the master seed, seed tree, logical clock, and event log for a single simulation run. Pass a reference to SimContext into every subsystem that needs deterministic randomness or event logging.

Implementations§

Source§

impl SimContext

Source

pub fn new(seed: VortexSeed) -> Self

Create a new simulation context from a master seed.

Source

pub fn from_u64(seed: u64) -> Self

Create from a simple u64 seed.

Source

pub fn seed(&self) -> VortexSeed

Get the master seed.

Source

pub fn seed_tree(&self) -> &SeedTree

Get the seed tree for deriving subsystem-specific RNGs.

Source

pub fn rng_for(&self, domain: &str) -> DetRng

Create a DetRng for a specific subsystem domain.

Source

pub fn logical_time_us(&self) -> u64

Get the current logical time in microseconds.

Source

pub fn advance_time_us(&mut self, delta_us: u64)

Advance logical time by the given microseconds.

Source

pub fn set_time_us(&mut self, time_us: u64)

Set logical time to an absolute value.

Source

pub fn log_event( &mut self, subsystem: Subsystem, description: impl Into<String>, ) -> SeqNo

Record an event in the event log.

Source

pub fn log_event_with_payload( &mut self, subsystem: Subsystem, description: impl Into<String>, payload: Vec<u8>, ) -> SeqNo

Record an event with a payload.

Source

pub fn event_log(&self) -> &SimEventLog

Get a reference to the event log.

Source

pub fn into_event_log(self) -> SimEventLog

Take ownership of the event log (consumes the context).

Trait Implementations§

Source§

impl Debug for SimContext

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.