Move StdTimeout to ectool under std feature
This commit is contained in:
parent
525e21033f
commit
ad5cd931e3
@ -14,5 +14,6 @@ name = "ectool"
|
||||
redox_hwio = "0.1.1"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
default = ["std"]
|
||||
stable = ["redox_hwio/stable"]
|
||||
std = []
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![no_std]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
pub use self::ec::Ec;
|
||||
mod ec;
|
||||
@ -22,4 +22,6 @@ pub use self::super_io::SuperIo;
|
||||
mod super_io;
|
||||
|
||||
pub use self::timeout::Timeout;
|
||||
#[cfg(feature = "std")]
|
||||
pub use self::timeout::StdTimeout;
|
||||
mod timeout;
|
||||
|
@ -2,10 +2,10 @@ use ectool::{
|
||||
Ec,
|
||||
Error,
|
||||
Firmware,
|
||||
StdTimeout,
|
||||
Spi,
|
||||
SpiRom,
|
||||
SpiTarget,
|
||||
Timeout,
|
||||
};
|
||||
use std::{
|
||||
env,
|
||||
@ -13,34 +13,10 @@ use std::{
|
||||
io,
|
||||
process,
|
||||
str::{self, FromStr},
|
||||
time::{Duration, Instant},
|
||||
time::Duration,
|
||||
thread,
|
||||
};
|
||||
|
||||
pub struct StdTimeout {
|
||||
instant: Instant,
|
||||
duration: Duration,
|
||||
}
|
||||
|
||||
impl StdTimeout {
|
||||
pub fn new(duration: Duration) -> Self {
|
||||
StdTimeout {
|
||||
instant: Instant::now(),
|
||||
duration
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Timeout for StdTimeout {
|
||||
fn reset(&mut self) {
|
||||
self.instant = Instant::now();
|
||||
}
|
||||
|
||||
fn running(&self) -> bool {
|
||||
self.instant.elapsed() < self.duration
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn iopl() {
|
||||
extern {
|
||||
fn iopl(level: isize) -> isize;
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user