Skip to main content

reifydb_runtime/context/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4//! The workspace's two sources of non-determinism, the wall clock and the RNG, behind mockable handles so a
5//! seeded run reproduces the same trace. Reaching into `std` for either instead defeats DST replay.
6
7pub mod clock;
8pub mod rng;
9
10use clock::{Clock, MockClock};
11use rng::Rng;
12
13use crate::version_epoch::VersionEpoch;
14
15#[derive(Clone)]
16pub struct RuntimeContext {
17	pub clock: Clock,
18	pub rng: Rng,
19	pub version_epoch: VersionEpoch,
20}
21
22impl RuntimeContext {
23	pub fn new(clock: Clock, rng: Rng, version_epoch: VersionEpoch) -> Self {
24		Self {
25			clock,
26			rng,
27			version_epoch,
28		}
29	}
30
31	pub fn with_clock(clock: Clock) -> Self {
32		Self {
33			clock,
34			rng: Rng::default(),
35			version_epoch: VersionEpoch::new(),
36		}
37	}
38
39	pub fn testing(initial_millis: u64, seed: u64) -> Self {
40		Self {
41			clock: Clock::Mock(MockClock::from_millis(initial_millis)),
42			rng: Rng::seeded(seed),
43			version_epoch: VersionEpoch::new(),
44		}
45	}
46}