Skip to content

Commit 5aef92c

Browse files
committed
Bring Duration into scope in time.rs
1 parent a0c00b2 commit 5aef92c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

vm/src/stdlib/time.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ mod time {
2828
naive::{NaiveDate, NaiveDateTime, NaiveTime},
2929
Datelike, Timelike,
3030
};
31+
use std::time::Duration;
3132

3233
#[allow(dead_code)]
3334
pub(super) const SEC_TO_MS: i64 = 1000;
@@ -46,7 +47,7 @@ mod time {
4647
#[allow(dead_code)]
4748
pub(super) const NS_TO_US: i64 = 1000;
4849

49-
fn duration_since_system_now(vm: &VirtualMachine) -> PyResult<std::time::Duration> {
50+
fn duration_since_system_now(vm: &VirtualMachine) -> PyResult<Duration> {
5051
use std::time::{SystemTime, UNIX_EPOCH};
5152

5253
SystemTime::now()
@@ -56,19 +57,19 @@ mod time {
5657

5758
// TODO: implement proper monotonic time for wasm/wasi.
5859
#[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> {
6061
duration_since_system_now(vm)
6162
}
6263

6364
// TODO: implement proper perf time for wasm/wasi.
6465
#[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> {
6667
duration_since_system_now(vm)
6768
}
6869

6970
#[cfg(not(unix))]
7071
#[pyfunction]
71-
fn sleep(dur: std::time::Duration) {
72+
fn sleep(dur: Duration) {
7273
std::thread::sleep(dur);
7374
}
7475

@@ -233,7 +234,7 @@ mod time {
233234
target_os = "fuchsia",
234235
target_os = "emscripten",
235236
)))]
236-
fn get_thread_time(vm: &VirtualMachine) -> PyResult<std::time::Duration> {
237+
fn get_thread_time(vm: &VirtualMachine) -> PyResult<Duration> {
237238
Err(vm.new_not_implemented_error("thread time unsupported in this system".to_owned()))
238239
}
239240

@@ -256,7 +257,7 @@ mod time {
256257
}
257258

258259
#[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> {
260261
let t: libc::tms = unsafe {
261262
let mut t = std::mem::MaybeUninit::uninit();
262263
if libc::times(t.as_mut_ptr()) == -1 {
@@ -270,7 +271,7 @@ mod time {
270271
#[cfg(not(target_os = "wasi"))]
271272
let freq = unsafe { libc::sysconf(libc::_SC_CLK_TCK) };
272273

273-
Ok(std::time::Duration::from_nanos(
274+
Ok(Duration::from_nanos(
274275
time_muldiv(t.tms_utime, SEC_TO_NS, freq) + time_muldiv(t.tms_stime, SEC_TO_NS, freq),
275276
))
276277
}
@@ -289,7 +290,7 @@ mod time {
289290
target_os = "redox",
290291
all(target_arch = "wasm32", not(target_os = "unknown"))
291292
)))]
292-
fn get_process_time(vm: &VirtualMachine) -> PyResult<std::time::Duration> {
293+
fn get_process_time(vm: &VirtualMachine) -> PyResult<Duration> {
293294
Err(vm.new_not_implemented_error("process time unsupported in this system".to_owned()))
294295
}
295296

0 commit comments

Comments
 (0)