Skip to main content

reifydb_runtime/context/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4//! Runtime context that bundles clock and RNG for the execution engine.
5
6pub mod clock;
7pub mod rng;
8
9use clock::{Clock, MockClock};
10use rng::Rng;
11
12/// A container for runtime services (clock, RNG) threaded through the execution engine.
13#[derive(Clone)]
14pub struct RuntimeContext {
15	pub clock: Clock,
16	pub rng: Rng,
17}
18
19impl Default for RuntimeContext {
20	fn default() -> Self {
21		Self {
22			clock: Clock::default(),
23			rng: Rng::default(),
24		}
25	}
26}
27
28impl RuntimeContext {
29	/// Create a runtime context with the given clock and RNG.
30	pub fn new(clock: Clock, rng: Rng) -> Self {
31		Self {
32			clock,
33			rng,
34		}
35	}
36
37	/// Create a runtime context with the given clock and OS RNG.
38	pub fn with_clock(clock: Clock) -> Self {
39		Self {
40			clock,
41			rng: Rng::default(),
42		}
43	}
44
45	/// Create a runtime context with a mock clock and seeded RNG (for testing).
46	pub fn testing(initial_millis: u64, seed: u64) -> Self {
47		Self {
48			clock: Clock::Mock(MockClock::from_millis(initial_millis)),
49			rng: Rng::seeded(seed),
50		}
51	}
52}