Skip to main content

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    pub const fn new(fixed_time: SystemTime) -> Self {
32        Self { fixed_time }
33    }
34
35    /// Returns the immutable time held by this clock.
36    ///
37    /// # Returns
38    ///
39    /// The configured fixed wall-clock value.
40    #[must_use]
41    pub const fn fixed_time(&self) -> SystemTime {
42        self.fixed_time
43    }
44}
45
46impl WallClock for FixedWallClock {
47    /// Returns the configured fixed wall time.
48    ///
49    /// # Returns
50    ///
51    /// The same fixed value for every call.
52    fn now(&self) -> SystemTime {
53        self.fixed_time
54    }
55}