Skip to content

Commit ad41b3d

Browse files
authored
Fix web_time usage for Timer (#851)
* Fix web_time usage for Timer * Remove #[allow(dead_code)]
1 parent cd7fc6e commit ad41b3d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/counters/timer.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@ use std::{
33
time::Duration,
44
};
55

6+
#[cfg(feature = "profiler")]
7+
use web_time::Instant;
8+
69
/// A timer.
710
#[derive(Copy, Clone, Debug, Default)]
811
pub struct Timer {
912
time: Duration,
10-
#[allow(dead_code)] // The field isn’t used if the `profiler` feature isn’t enabled.
11-
start: Option<std::time::Instant>,
13+
#[cfg(feature = "profiler")]
14+
start: Option<Instant>,
1215
}
1316

1417
impl Timer {
1518
/// Creates a new timer initialized to zero and not started.
1619
pub fn new() -> Self {
1720
Timer {
1821
time: Duration::from_secs(0),
22+
#[cfg(feature = "profiler")]
1923
start: None,
2024
}
2125
}
@@ -30,7 +34,7 @@ impl Timer {
3034
#[cfg(feature = "profiler")]
3135
{
3236
self.time = Duration::from_secs(0);
33-
self.start = Some(web_time::Instant::now());
37+
self.start = Some(Instant::now());
3438
}
3539
}
3640

@@ -39,7 +43,7 @@ impl Timer {
3943
#[cfg(feature = "profiler")]
4044
{
4145
if let Some(start) = self.start {
42-
self.time += web_time::Instant::now().duration_since(start);
46+
self.time += Instant::now().duration_since(start);
4347
}
4448
self.start = None;
4549
}
@@ -49,7 +53,7 @@ impl Timer {
4953
pub fn resume(&mut self) {
5054
#[cfg(feature = "profiler")]
5155
{
52-
self.start = Some(web_time::Instant::now());
56+
self.start = Some(Instant::now());
5357
}
5458
}
5559

0 commit comments

Comments
 (0)