1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use super::{lowlevel, UnixTimeStampError};
use std::time::{Duration, SystemTime};
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct UnixTimeStamp(pub(crate) lowlevel::UnixTimeStamp);
impl UnixTimeStamp {
pub fn new(system_time: SystemTime) -> Result<Self, UnixTimeStampError> {
lowlevel::UnixTimeStamp::new(system_time).map(Self)
}
pub const fn unix_epoch() -> Self {
Self(lowlevel::UnixTimeStamp::unix_epoch())
}
pub fn from_raw(elapsed: u32) -> Option<Self> {
lowlevel::UnixTimeStamp::from_raw(elapsed).map(Self)
}
pub fn into_raw(self) -> u32 {
self.0.into_raw()
}
pub fn as_duration(self) -> Duration {
self.0.as_duration()
}
pub fn as_system_time(self) -> SystemTime {
self.0.as_system_time()
}
}