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 std::time::SystemTime;
11
12use crate::WallClock;
13
14/// A wall clock that always returns one fixed time.
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub struct FixedWallClock {
17    /// Immutable wall-clock value returned by every sample.
18    fixed_time: SystemTime,
19}
20
21impl FixedWallClock {
22    /// Creates a clock that always returns `fixed_time`.
23    ///
24    /// # Parameters
25    ///
26    /// * `fixed_time` - Wall-clock value returned by every sample.
27    ///
28    /// # Returns
29    ///
30    /// A wall clock fixed at `fixed_time`.
31    #[must_use]
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    pub const fn fixed_time(&self) -> SystemTime {
43        self.fixed_time
44    }
45}
46
47impl WallClock for FixedWallClock {
48    /// Returns the configured fixed wall time.
49    ///
50    /// # Returns
51    ///
52    /// The same fixed value for every call.
53    fn now(&self) -> SystemTime {
54        self.fixed_time
55    }
56}