qubit_clock/wall/fixed_wall_clock.rs
1// =============================================================================
2// Copyright (c) 2025 - 2026 Haixing Hu.
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6// Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Defines an immutable fixed wall clock.
9
10use crate::WallClock;
11use std::time::SystemTime;
12
13/// A wall clock that always returns one fixed time.
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15pub struct FixedWallClock {
16 /// Immutable wall-clock value returned by every sample.
17 fixed_time: SystemTime,
18}
19
20impl FixedWallClock {
21 /// Creates a clock that always returns `fixed_time`.
22 ///
23 /// # Parameters
24 ///
25 /// * `fixed_time` - Wall-clock value returned by every sample.
26 ///
27 /// # Returns
28 ///
29 /// A wall clock fixed at `fixed_time`.
30 #[must_use]
31 #[inline(always)]
32 pub const fn new(fixed_time: SystemTime) -> Self {
33 Self { fixed_time }
34 }
35
36 /// Returns the immutable time held by this clock.
37 ///
38 /// # Returns
39 ///
40 /// The configured fixed wall-clock value.
41 #[must_use]
42 #[inline(always)]
43 pub const fn fixed_time(&self) -> SystemTime {
44 self.fixed_time
45 }
46}
47
48impl WallClock for FixedWallClock {
49 /// Returns the configured fixed wall time.
50 ///
51 /// # Returns
52 ///
53 /// The same fixed value for every call.
54 #[inline(always)]
55 fn now(&self) -> SystemTime {
56 self.fixed_time
57 }
58}