Skip to main content

reifydb_runtime/context/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4//! Sources of non-determinism the workspace consumes: the wall clock and the random number generator. Both have
5//! mockable variants so a deterministic-simulation run replaces them with seeded equivalents and reproduces the
6//! same trace bit-for-bit. Anything in the workspace that needs the time of day or a random value reaches for
7//! these handles instead of pulling from `std`.
8
9pub mod clock;
10pub mod rng;
11
12use clock::{Clock, MockClock};
13use rng::Rng;
14
15#[derive(Clone)]
16pub struct RuntimeContext {
17	pub clock: Clock,
18	pub rng: Rng,
19}
20
21impl RuntimeContext {
22	pub fn new(clock: Clock, rng: Rng) -> Self {
23		Self {
24			clock,
25			rng,
26		}
27	}
28
29	pub fn with_clock(clock: Clock) -> Self {
30		Self {
31			clock,
32			rng: Rng::default(),
33		}
34	}
35
36	pub fn testing(initial_millis: u64, seed: u64) -> Self {
37		Self {
38			clock: Clock::Mock(MockClock::from_millis(initial_millis)),
39			rng: Rng::seeded(seed),
40		}
41	}
42}