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"
|
redox_hwio = "0.1.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = ["std"]
|
||||||
stable = ["redox_hwio/stable"]
|
stable = ["redox_hwio/stable"]
|
||||||
|
std = []
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#![no_std]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
pub use self::ec::Ec;
|
pub use self::ec::Ec;
|
||||||
mod ec;
|
mod ec;
|
||||||
@ -22,4 +22,6 @@ pub use self::super_io::SuperIo;
|
|||||||
mod super_io;
|
mod super_io;
|
||||||
|
|
||||||
pub use self::timeout::Timeout;
|
pub use self::timeout::Timeout;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
pub use self::timeout::StdTimeout;
|
||||||
mod timeout;
|
mod timeout;
|
||||||
|
@ -2,10 +2,10 @@ use ectool::{
|
|||||||
Ec,
|
Ec,
|
||||||
Error,
|
Error,
|
||||||
Firmware,
|
Firmware,
|
||||||
|
StdTimeout,
|
||||||
Spi,
|
Spi,
|
||||||
SpiRom,
|
SpiRom,
|
||||||
SpiTarget,
|
SpiTarget,
|
||||||
Timeout,
|
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env,
|
||||||
@ -13,34 +13,10 @@ use std::{
|
|||||||
io,
|
io,
|
||||||
process,
|
process,
|
||||||
str::{self, FromStr},
|
str::{self, FromStr},
|
||||||
time::{Duration, Instant},
|
time::Duration,
|
||||||
thread,
|
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() {
|
unsafe fn iopl() {
|
||||||
extern {
|
extern {
|
||||||
fn iopl(level: isize) -> isize;
|
fn iopl(level: isize) -> isize;
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
#[cfg(feature = "std")]
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! timeout {
|
macro_rules! timeout {
|
||||||
($t:expr, $f:expr) => {{
|
($t:expr, $f:expr) => {{
|
||||||
@ -25,3 +28,30 @@ pub trait Timeout {
|
|||||||
fn reset(&mut self);
|
fn reset(&mut self);
|
||||||
fn running(&self) -> bool;
|
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