Fix web_time usage for Timer (#851)
* Fix web_time usage for Timer * Remove #[allow(dead_code)]
This commit is contained in:
@@ -3,12 +3,15 @@ use std::{
|
|||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "profiler")]
|
||||||
|
use web_time::Instant;
|
||||||
|
|
||||||
/// A timer.
|
/// A timer.
|
||||||
#[derive(Copy, Clone, Debug, Default)]
|
#[derive(Copy, Clone, Debug, Default)]
|
||||||
pub struct Timer {
|
pub struct Timer {
|
||||||
time: Duration,
|
time: Duration,
|
||||||
#[allow(dead_code)] // The field isn’t used if the `profiler` feature isn’t enabled.
|
#[cfg(feature = "profiler")]
|
||||||
start: Option<std::time::Instant>,
|
start: Option<Instant>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Timer {
|
impl Timer {
|
||||||
@@ -16,6 +19,7 @@ impl Timer {
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Timer {
|
Timer {
|
||||||
time: Duration::from_secs(0),
|
time: Duration::from_secs(0),
|
||||||
|
#[cfg(feature = "profiler")]
|
||||||
start: None,
|
start: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,7 +34,7 @@ impl Timer {
|
|||||||
#[cfg(feature = "profiler")]
|
#[cfg(feature = "profiler")]
|
||||||
{
|
{
|
||||||
self.time = Duration::from_secs(0);
|
self.time = Duration::from_secs(0);
|
||||||
self.start = Some(web_time::Instant::now());
|
self.start = Some(Instant::now());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +43,7 @@ impl Timer {
|
|||||||
#[cfg(feature = "profiler")]
|
#[cfg(feature = "profiler")]
|
||||||
{
|
{
|
||||||
if let Some(start) = self.start {
|
if let Some(start) = self.start {
|
||||||
self.time += web_time::Instant::now().duration_since(start);
|
self.time += Instant::now().duration_since(start);
|
||||||
}
|
}
|
||||||
self.start = None;
|
self.start = None;
|
||||||
}
|
}
|
||||||
@@ -49,7 +53,7 @@ impl Timer {
|
|||||||
pub fn resume(&mut self) {
|
pub fn resume(&mut self) {
|
||||||
#[cfg(feature = "profiler")]
|
#[cfg(feature = "profiler")]
|
||||||
{
|
{
|
||||||
self.start = Some(web_time::Instant::now());
|
self.start = Some(Instant::now());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user