@@ -28,6 +28,7 @@ mod time {
28
28
naive:: { NaiveDate , NaiveDateTime , NaiveTime } ,
29
29
Datelike , Timelike ,
30
30
} ;
31
+ use std:: time:: Duration ;
31
32
32
33
#[ allow( dead_code) ]
33
34
pub ( super ) const SEC_TO_MS : i64 = 1000 ;
@@ -46,7 +47,7 @@ mod time {
46
47
#[ allow( dead_code) ]
47
48
pub ( super ) const NS_TO_US : i64 = 1000 ;
48
49
49
- fn duration_since_system_now ( vm : & VirtualMachine ) -> PyResult < std :: time :: Duration > {
50
+ fn duration_since_system_now ( vm : & VirtualMachine ) -> PyResult < Duration > {
50
51
use std:: time:: { SystemTime , UNIX_EPOCH } ;
51
52
52
53
SystemTime :: now ( )
@@ -56,19 +57,19 @@ mod time {
56
57
57
58
// TODO: implement proper monotonic time for wasm/wasi.
58
59
#[ cfg( not( any( unix, windows) ) ) ]
59
- fn get_monotonic_time ( vm : & VirtualMachine ) -> PyResult < std :: time :: Duration > {
60
+ fn get_monotonic_time ( vm : & VirtualMachine ) -> PyResult < Duration > {
60
61
duration_since_system_now ( vm)
61
62
}
62
63
63
64
// TODO: implement proper perf time for wasm/wasi.
64
65
#[ cfg( not( any( unix, windows) ) ) ]
65
- fn get_perf_time ( vm : & VirtualMachine ) -> PyResult < std :: time :: Duration > {
66
+ fn get_perf_time ( vm : & VirtualMachine ) -> PyResult < Duration > {
66
67
duration_since_system_now ( vm)
67
68
}
68
69
69
70
#[ cfg( not( unix) ) ]
70
71
#[ pyfunction]
71
- fn sleep ( dur : std :: time :: Duration ) {
72
+ fn sleep ( dur : Duration ) {
72
73
std:: thread:: sleep ( dur) ;
73
74
}
74
75
@@ -233,7 +234,7 @@ mod time {
233
234
target_os = "fuchsia" ,
234
235
target_os = "emscripten" ,
235
236
) ) ) ]
236
- fn get_thread_time ( vm : & VirtualMachine ) -> PyResult < std :: time :: Duration > {
237
+ fn get_thread_time ( vm : & VirtualMachine ) -> PyResult < Duration > {
237
238
Err ( vm. new_not_implemented_error ( "thread time unsupported in this system" . to_owned ( ) ) )
238
239
}
239
240
@@ -256,7 +257,7 @@ mod time {
256
257
}
257
258
258
259
#[ cfg( all( target_arch = "wasm32" , not( target_os = "unknown" ) ) ) ]
259
- fn get_process_time ( vm : & VirtualMachine ) -> PyResult < std :: time :: Duration > {
260
+ fn get_process_time ( vm : & VirtualMachine ) -> PyResult < Duration > {
260
261
let t: libc:: tms = unsafe {
261
262
let mut t = std:: mem:: MaybeUninit :: uninit ( ) ;
262
263
if libc:: times ( t. as_mut_ptr ( ) ) == -1 {
@@ -270,7 +271,7 @@ mod time {
270
271
#[ cfg( not( target_os = "wasi" ) ) ]
271
272
let freq = unsafe { libc:: sysconf ( libc:: _SC_CLK_TCK) } ;
272
273
273
- Ok ( std :: time :: Duration :: from_nanos (
274
+ Ok ( Duration :: from_nanos (
274
275
time_muldiv ( t. tms_utime , SEC_TO_NS , freq) + time_muldiv ( t. tms_stime , SEC_TO_NS , freq) ,
275
276
) )
276
277
}
@@ -289,7 +290,7 @@ mod time {
289
290
target_os = "redox" ,
290
291
all( target_arch = "wasm32" , not( target_os = "unknown" ) )
291
292
) ) ) ]
292
- fn get_process_time ( vm : & VirtualMachine ) -> PyResult < std :: time :: Duration > {
293
+ fn get_process_time ( vm : & VirtualMachine ) -> PyResult < Duration > {
293
294
Err ( vm. new_not_implemented_error ( "process time unsupported in this system" . to_owned ( ) ) )
294
295
}
295
296
0 commit comments