pub struct EnvHandle { /* private fields */ }Expand description
A lightweight handle to the simulation environment, intended to be cloned and passed into spawned processes.
Both SimEnv and all EnvHandle clones share the same underlying
SimState and the same RandomSource.
Implementations§
Source§impl EnvHandle
impl EnvHandle
Sourcepub fn rng(&self) -> impl RngCore + '_
pub fn rng(&self) -> impl RngCore + '_
Borrow the shared RNG mutably.
The returned guard implements rand::RngCore, so it works with the
rng::sample transforms and with rand_distr
distributions alike. Sample before awaiting — the guard cannot be held
across an .await point.
use simu::{SimEnv, rng::sample};
let env = SimEnv::with_seed(0);
let h = env.handle();
let duration = sample::exponential(&mut h.rng(), 20.0); // mean = 20
assert!(duration >= 0.0);Sourcepub fn timeout(&self, delay: f64) -> Timeout ⓘ
pub fn timeout(&self, delay: f64) -> Timeout ⓘ
Create a Timeout that resolves after delay simulated time units.
The deadline is computed when the Timeout is created
(now() + delay), not when it is first awaited — relevant when a
Timeout is stored and raced later inside any_of!.
§Panics
Panics if delay is negative or not finite (NaN / infinity). Simulated
time is monotonic, so a negative delay is a programming error; a zero
delay is allowed and fires on the next event-loop iteration.
Sourcepub fn event(&self) -> (EventTrigger, EventAwaitable)
pub fn event(&self) -> (EventTrigger, EventAwaitable)
Create a paired (EventTrigger, EventAwaitable) for inter-process signalling.
Sourcepub fn spawn<F>(&self, future: F) -> ProcessHandle<F::Output> ⓘ
pub fn spawn<F>(&self, future: F) -> ProcessHandle<F::Output> ⓘ
Spawn a child process from within a running process.
Returns a ProcessHandle that resolves to the process’s output when
it finishes. Drop the handle to detach (fire-and-forget).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for EnvHandle
impl !Send for EnvHandle
impl !Sync for EnvHandle
impl !UnwindSafe for EnvHandle
impl Freeze for EnvHandle
impl Unpin for EnvHandle
impl UnsafeUnpin for EnvHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more