Skip to content

Commit de0a041

Browse files
authored
refactor: drop constraint on Future's Output (#213)
1 parent f68b793 commit de0a041

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

backon/src/blocking_sleep.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub type DefaultBlockingSleeper = StdSleeper;
3636
///
3737
/// Users should enable a feature of this crate that provides a valid [`Sleeper`] implementation when this type appears in compilation errors. Alternatively, a custom [`Sleeper`] implementation should be provided where necessary, such as in [`crate::Retry::sleeper`].
3838
#[doc(hidden)]
39+
#[allow(dead_code)]
3940
#[derive(Clone, Copy, Debug, Default)]
4041
pub struct PleaseEnableAFeatureOrProvideACustomSleeper;
4142

backon/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
//! Ok("hello, world!".to_string())
9999
//! }
100100
//!
101-
//! #[tokio::main]
101+
//! #[tokio::main(flavor = "current_thread")]
102102
//! async fn main() -> Result<()> {
103103
//! let content = fetch
104104
//! // Retry with exponential backoff

backon/src/retry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ where
118118
{
119119
/// Set the sleeper for retrying.
120120
///
121-
/// The sleeper should implement the [`Sleeper`] trait. The simplest way is to use a closure that returns a `Future<Output=()>`.
121+
/// The sleeper should implement the [`Sleeper`] trait. The simplest way is to use a closure that returns a `Future`.
122122
///
123123
/// If not specified, we use the [`DefaultSleeper`].
124124
///
@@ -344,7 +344,7 @@ where
344344

345345
/// State maintains internal state of retry.
346346
#[derive(Default)]
347-
enum State<T, E, Fut: Future<Output = Result<T, E>>, SleepFut: Future<Output = ()>> {
347+
enum State<T, E, Fut: Future<Output = Result<T, E>>, SleepFut: Future> {
348348
#[default]
349349
Idle,
350350
Polling(Fut),

backon/src/retry_with_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ where
151151
{
152152
/// Set the sleeper for retrying.
153153
///
154-
/// The sleeper should implement the [`Sleeper`] trait. The simplest way is to use a closure that returns a `Future<Output=()>`.
154+
/// The sleeper should implement the [`Sleeper`] trait. The simplest way is to use a closure that returns a `Future`.
155155
///
156156
/// If not specified, we use the [`DefaultSleeper`].
157157
pub fn sleep<SN: Sleeper>(
@@ -284,7 +284,7 @@ where
284284
}
285285

286286
/// State maintains internal state of retry.
287-
enum State<T, E, Ctx, Fut: Future<Output = (Ctx, Result<T, E>)>, SleepFut: Future<Output = ()>> {
287+
enum State<T, E, Ctx, Fut: Future<Output = (Ctx, Result<T, E>)>, SleepFut: Future> {
288288
Idle(Option<Ctx>),
289289
Polling(Fut),
290290
Sleeping((Option<Ctx>, SleepFut)),

backon/src/sleep.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::time::Duration;
55
/// A sleeper is used to generate a future that completes after a specified duration.
66
pub trait Sleeper: 'static {
77
/// The future returned by the `sleep` method.
8-
type Sleep: Future<Output = ()>;
8+
type Sleep: Future;
99

1010
/// Create a future that completes after a set period.
1111
fn sleep(&self, dur: Duration) -> Self::Sleep;
@@ -15,16 +15,16 @@ pub trait Sleeper: 'static {
1515
/// It does not provide actual functionality.
1616
#[doc(hidden)]
1717
pub trait MaybeSleeper: 'static {
18-
type Sleep: Future<Output = ()>;
18+
type Sleep: Future;
1919
}
2020

2121
/// All `Sleeper` will implement `MaybeSleeper`, but not vice versa.
2222
impl<T: Sleeper + ?Sized> MaybeSleeper for T {
2323
type Sleep = <T as Sleeper>::Sleep;
2424
}
2525

26-
/// All `Fn(Duration) -> impl Future<Output = ()>` implements `Sleeper`.
27-
impl<F: Fn(Duration) -> Fut + 'static, Fut: Future<Output = ()>> Sleeper for F {
26+
/// All `Fn(Duration) -> impl Future` implements `Sleeper`.
27+
impl<F: Fn(Duration) -> Fut + 'static, Fut: Future> Sleeper for F {
2828
type Sleep = Fut;
2929

3030
fn sleep(&self, dur: Duration) -> Self::Sleep {
@@ -52,6 +52,7 @@ pub type DefaultSleeper = GlooTimersSleep;
5252
///
5353
/// Users should enable a feature of this crate that provides a valid [`Sleeper`] implementation when this type appears in compilation errors. Alternatively, a custom [`Sleeper`] implementation should be provided where necessary, such as in [`crate::Retry::sleeper`].
5454
#[doc(hidden)]
55+
#[allow(dead_code)]
5556
#[derive(Clone, Copy, Debug, Default)]
5657
pub struct PleaseEnableAFeatureOrProvideACustomSleeper;
5758

0 commit comments

Comments
 (0)