@@ -22,13 +22,8 @@ use alloc::vec::Vec;
22
22
#[ cfg( all( feature = "alloc" , not( feature = "std" ) ) ) ]
23
23
use core:: num;
24
24
25
- #[ cfg( target_arch = "wasm32" ) ]
26
- use instant:: SystemTime ;
27
25
use serde:: { Deserialize , Serialize } ;
28
26
29
- #[ cfg( target_arch = "wasm32" ) ]
30
- const UNIX_EPOCH : SystemTime = SystemTime :: UNIX_EPOCH ;
31
-
32
27
/// Helper trait for acquiring time in `no_std` environments.
33
28
pub trait TimeSupplier {
34
29
/// The current time from the specified `TimeSupplier`
@@ -61,24 +56,37 @@ impl TimeSupplier for InstantWasm32 {
61
56
type Now = InstantWasm32 ;
62
57
type StartingPoint = std:: time:: SystemTime ;
63
58
59
+ fn now ( & self ) -> Self :: StartingPoint {
60
+ SystemTime :: now ( )
61
+ }
62
+
64
63
fn instant_now ( & self ) -> Self :: Now {
65
64
InstantWasm32 :: now ( )
66
65
}
67
66
68
- fn starting_point ( & self ) -> Self :: Now {
67
+ fn duration_since_starting_point ( & self , now : Self :: StartingPoint ) -> Duration {
68
+ now. duration_since ( self . starting_point ( ) )
69
+ . expect ( "duration_since panicked" )
70
+ }
71
+
72
+ fn starting_point ( & self ) -> Self :: StartingPoint {
69
73
std:: time:: UNIX_EPOCH
70
74
}
71
75
72
- fn elapsed_since ( & self , now : Self :: Now , since : Self :: Now ) -> Duration {
76
+ fn elapsed_instant_since ( & self , now : Self :: Now , since : Self :: Now ) -> Duration {
73
77
now - since
74
78
}
75
79
80
+ fn elapsed_since ( & self , now : Self :: StartingPoint , since : Self :: StartingPoint ) -> Duration {
81
+ now. duration_since ( since) . expect ( "duration_since panicked" )
82
+ }
83
+
76
84
fn as_i64 ( & self , duration : Duration ) -> i64 {
77
85
duration. as_millis ( ) as i64
78
86
}
79
87
80
88
fn to_timestamp ( & self , duration : Duration ) -> Timestamp {
81
- Timestamp ( duration . as_millis ( ) as i64 )
89
+ Timestamp ( self . as_i64 ( duration ) )
82
90
}
83
91
}
84
92
0 commit comments