Move StdTimeout to ectool under std feature
This commit is contained in:
committed by
Jeremy Soller
parent
525e21033f
commit
ad5cd931e3
@ -1,3 +1,6 @@
|
||||
#[cfg(feature = "std")]
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! timeout {
|
||||
($t:expr, $f:expr) => {{
|
||||
@ -25,3 +28,30 @@ pub trait Timeout {
|
||||
fn reset(&mut self);
|
||||
fn running(&self) -> bool;
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub struct StdTimeout {
|
||||
instant: Instant,
|
||||
duration: Duration,
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl StdTimeout {
|
||||
pub fn new(duration: Duration) -> Self {
|
||||
StdTimeout {
|
||||
instant: Instant::now(),
|
||||
duration
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Timeout for StdTimeout {
|
||||
fn reset(&mut self) {
|
||||
self.instant = Instant::now();
|
||||
}
|
||||
|
||||
fn running(&self) -> bool {
|
||||
self.instant.elapsed() < self.duration
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user