Skip to content

Commit

Permalink
Require to define EmbassySleeper explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
wackazong committed Dec 24, 2024
1 parent 9b27b9a commit a21566f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 19 deletions.
2 changes: 1 addition & 1 deletion backon/src/blocking_sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<F: Fn(Duration) + 'static> BlockingSleeper for F {
/// The default implementation of `Sleeper` when no features are enabled.
///
/// It will fail to compile if a containing [`Retry`][crate::Retry] is `.await`ed without calling [`Retry::sleep`][crate::Retry::sleep] to provide a valid sleeper.
#[cfg(all(not(feature = "std-blocking-sleep"), not(feature = "embassy-sleep")))]
#[cfg(not(feature = "std-blocking-sleep"))]
pub type DefaultBlockingSleeper = PleaseEnableAFeatureOrProvideACustomSleeper;
/// The default implementation of `Sleeper` while feature `std-blocking-sleep` enabled.
///
Expand Down
10 changes: 1 addition & 9 deletions backon/src/embassy_timer_sleep.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{blocking_sleep::MaybeBlockingSleeper, BlockingSleeper, Sleeper};
use crate::{BlockingSleeper, Sleeper};
use core::time::Duration;

/// A no_std async sleeper based on the embassy framework (https://embassy.dev)
Expand All @@ -13,9 +13,6 @@ impl Sleeper for EmbassySleeper {
}
}

/// The default async sleeper for no_std environments
pub type DefaultSleeper = EmbassySleeper;

/// A no_std blocking sleeper based on the embassy framework (https://embassy.dev)
#[derive(Clone, Copy, Debug, Default)]
pub struct EmbassyBlockingSleeper;
Expand All @@ -25,8 +22,3 @@ impl BlockingSleeper for EmbassySleeper {
embassy_time::block_for(embassy_time::Duration::from_millis(dur.as_millis() as u64));
}
}

impl MaybeBlockingSleeper for EmbassyBlockingSleeper {}

/// The default blocking sleeper for no_std environments
pub type DefaultBlockingSleeper = EmbassyBlockingSleeper;
6 changes: 2 additions & 4 deletions backon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ pub use retry_with_context::RetryWithContext;
pub use retry_with_context::RetryableWithContext;

mod sleep;
#[cfg(feature = "std")]
pub use sleep::DefaultSleeper;
#[cfg(all(target_arch = "wasm32", feature = "gloo-timers-sleep"))]
pub use sleep::GlooTimersSleep;
Expand All @@ -182,17 +181,16 @@ pub use blocking_retry_with_context::{BlockingRetryWithContext, BlockingRetryabl

mod blocking_sleep;
pub use blocking_sleep::BlockingSleeper;
#[cfg(feature = "std")]
pub use blocking_sleep::DefaultBlockingSleeper;
#[cfg(feature = "std-blocking-sleep")]
pub use blocking_sleep::StdSleeper;

#[cfg(feature = "embassy-sleep")]
mod embassy_timer_sleep;
#[cfg(feature = "embassy-sleep")]
pub use embassy_timer_sleep::DefaultBlockingSleeper;
pub use embassy_timer_sleep::EmbassyBlockingSleeper;
#[cfg(feature = "embassy-sleep")]
pub use embassy_timer_sleep::DefaultSleeper;
pub use embassy_timer_sleep::EmbassySleeper;

#[cfg(docsrs)]
pub mod docs;
6 changes: 1 addition & 5 deletions backon/src/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ impl<F: Fn(Duration) -> Fut + 'static, Fut: Future<Output = ()>> Sleeper for F {
/// The default implementation of `Sleeper` when no features are enabled.
///
/// It will fail to compile if a containing [`Retry`][crate::Retry] is `.await`ed without calling [`Retry::sleep`][crate::Retry::sleep] to provide a valid sleeper.
#[cfg(all(
not(feature = "tokio-sleep"),
not(feature = "gloo-timers-sleep"),
not(feature = "embassy-sleep")
))]
#[cfg(all(not(feature = "tokio-sleep"), not(feature = "gloo-timers-sleep"),))]
pub type DefaultSleeper = PleaseEnableAFeatureOrProvideACustomSleeper;
/// The default implementation of `Sleeper` while feature `tokio-sleep` enabled.
///
Expand Down

0 comments on commit a21566f

Please sign in to comment.