Skip to main content

reifydb_runtime/context/
mod.rs

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