diff --git a/.github/workflows/check_pr.yml b/.github/workflows/check_pr.yml index 7d93600..943931b 100644 --- a/.github/workflows/check_pr.yml +++ b/.github/workflows/check_pr.yml @@ -13,6 +13,7 @@ jobs: feature: - async-std - futures + - instant - tokio - wasm-bindgen steps: @@ -27,10 +28,10 @@ jobs: override: true - name: Run cargo check - run: cargo check --features=${{ matrix.feature }} + run: cargo check --no-default-features --features=${{ matrix.feature }} - name: Run cargo test - run: cargo test --features=${{ matrix.feature }} + run: cargo test --no-default-features --features=${{ matrix.feature }} lints: name: Lints @@ -51,4 +52,4 @@ jobs: run: cargo fmt --all -- --check - name: Run cargo clippy - run: cargo clippy -- -D warnings \ No newline at end of file + run: cargo clippy -- -D warnings diff --git a/Cargo.toml b/Cargo.toml index 52635ab..fc43f29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ travis-ci = { repository = "ihrwein/backoff" } [dependencies] async_std_1 = { package = "async-std", version = "1.9", optional = true } futures-core = { version = "0.3.8", default-features = false, optional = true } -instant = "0.1" +instant = { version = "0.1", optional = true } pin-project-lite = { version = "0.2.7", optional = true } rand = "0.8" getrandom = "0.2" @@ -32,7 +32,7 @@ tokio_1 = { package = "tokio", version = "1.0", features = ["macros", "time", "r futures-executor = "0.3" [features] -default = [] +default = ["instant"] wasm-bindgen = ["instant/wasm-bindgen", "getrandom/js"] futures = ["futures-core", "pin-project-lite"] tokio = ["futures", "tokio_1"] diff --git a/src/clock.rs b/src/clock.rs index f3ad9a0..acbc578 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -1,4 +1,4 @@ -use instant::Instant; +use crate::Instant; /// Clock returns the current time. pub trait Clock { diff --git a/src/error.rs b/src/error.rs index 5c32310..0ebebe8 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,7 +1,6 @@ use std::error; use std::fmt; - -use instant::Duration; +use std::time::Duration; /// Error is the error value in an operation's /// result. diff --git a/src/exponential.rs b/src/exponential.rs index abaa28d..9c54d4c 100644 --- a/src/exponential.rs +++ b/src/exponential.rs @@ -1,10 +1,10 @@ -use instant::Instant; use std::marker::PhantomData; use std::time::Duration; use crate::backoff::Backoff; use crate::clock::Clock; use crate::default; +use crate::Instant; #[derive(Debug)] pub struct ExponentialBackoff { diff --git a/src/instant.rs b/src/instant.rs new file mode 100644 index 0000000..c30e34d --- /dev/null +++ b/src/instant.rs @@ -0,0 +1,8 @@ +#[cfg(feature = "instant")] +pub use instant::Instant; + +#[cfg(all(feature = "tokio_1", not(feature = "instant")))] +pub use tokio_1::time::Instant; + +#[cfg(not(any(feature = "tokio_1", feature = "instant")))] +pub use std::time::Instant; diff --git a/src/lib.rs b/src/lib.rs index 0196431..928a004 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -216,6 +216,7 @@ pub mod backoff; mod clock; pub mod default; mod error; +mod instant; pub mod exponential; #[cfg(feature = "futures")] @@ -226,6 +227,7 @@ mod retry; pub use crate::clock::{Clock, SystemClock}; pub use crate::error::Error; +pub use crate::instant::Instant; pub use crate::retry::{retry, retry_notify, Notify}; /// Exponential backoff policy with system's clock. diff --git a/tests/exponential.rs b/tests/exponential.rs index 45bb9e9..fe497da 100644 --- a/tests/exponential.rs +++ b/tests/exponential.rs @@ -1,11 +1,9 @@ extern crate backoff; -extern crate instant; use backoff::backoff::Backoff; use backoff::exponential::ExponentialBackoff; -use backoff::{Clock, SystemClock}; +use backoff::{Clock, Instant, SystemClock}; -use instant::Instant; use std::cell::RefCell; use std::time::Duration;