libsw_core/instant_impls/
std_systemtime.rs

1// libsw: stopwatch library
2// copyright (C) 2022-2023 Ula Shipman <ula.hello@mailbox.org>
3// licensed under MIT OR Apache-2.0
4
5extern crate std;
6
7use ::core::time::Duration;
8
9use crate::Instant;
10
11impl Instant for ::std::time::SystemTime {
12    fn now() -> Self {
13        Self::now()
14    }
15
16    fn checked_add(&self, duration: Duration) -> Option<Self> {
17        self.checked_add(duration)
18    }
19
20    fn checked_sub(&self, duration: Duration) -> Option<Self> {
21        self.checked_sub(duration)
22    }
23
24    fn saturating_duration_since(&self, earlier: Self) -> Duration {
25        // NOTE: SystemTime is not monotonic. see its documentation for
26        // implications
27        self.duration_since(earlier).unwrap_or(Duration::ZERO)
28    }
29}