]>
git.proxmox.com Git - rustc.git/blob - src/libstd/sys/wasm/time.rs
1 use crate::time
::Duration
;
3 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
4 pub struct Instant(Duration
);
6 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
7 pub struct SystemTime(Duration
);
9 pub const UNIX_EPOCH
: SystemTime
= SystemTime(Duration
::from_secs(0));
12 pub fn now() -> Instant
{
13 panic
!("time not implemented on wasm32-unknown-unknown")
16 pub const fn zero() -> Instant
{
17 Instant(Duration
::from_secs(0))
20 pub fn actually_monotonic() -> bool
{
24 pub fn checked_sub_instant(&self, other
: &Instant
) -> Option
<Duration
> {
25 self.0.checked_sub(other
.0)
28 pub fn checked_add_duration(&self, other
: &Duration
) -> Option
<Instant
> {
29 Some(Instant(self.0.checked_add(*other
)?
))
32 pub fn checked_sub_duration(&self, other
: &Duration
) -> Option
<Instant
> {
33 Some(Instant(self.0.checked_sub(*other
)?
))
38 pub fn now() -> SystemTime
{
39 panic
!("time not implemented on wasm32-unknown-unknown")
42 pub fn sub_time(&self, other
: &SystemTime
) -> Result
<Duration
, Duration
> {
43 self.0.checked_sub(other
.0).ok_or_else(|| other
.0 - self.0)
46 pub fn checked_add_duration(&self, other
: &Duration
) -> Option
<SystemTime
> {
47 Some(SystemTime(self.0.checked_add(*other
)?
))
50 pub fn checked_sub_duration(&self, other
: &Duration
) -> Option
<SystemTime
> {
51 Some(SystemTime(self.0.checked_sub(*other
)?
))