pub fn build<Strategy, Error>(
        &self,
        strategy: impl Fn(Duration) -> Strategy + Sync + Send + 'static,
    ) -> impl Fn(usize, &Error) -> Strategy + Sync + Send + 'static
    where
        Strategy: Default + Sync + Send + 'static,
    {
        let initial_delay = self.initial_delay;
        let factor = self.exponent;
        let max_retries = self.max_retries;
        let jitter = self.jitter;
        let max_delay = self.max_delay;

        move |retries, _| {
            if retries <= max_retries {
                let mut delay =
                    initial_delay.mul_f64(factor.abs().powf(retries.min(max_retries) as f64));
                delay = max_delay.unwrap_or(delay).min(delay);
                let random_jitter = jitter.mul_f64(rand::random());
                if rand::random() {
                    delay += random_jitter;
                } else {
                    delay -= random_jitter.min(delay);
                }
                strategy(delay)
            } else {
                Strategy::default()
            }
        }
    }
/// Use this [`Backoff`] to generate a closure that implements the backoff strategy it
/// describes, given a constructor for some kind of delay strategy parameterized by a
/// `Duration`.
///
/// This assumes that the [`default`](Default::default) for the given `Strategy` type represents
/// failure.
Use this [`Backoff`] to generate a closure that implements the backoff strategy it
describes, given a constructor for some kind of delay strategy parameterized by a
`Duration`.

This assumes that the [`default`](Default::default) for the given `Strategy` type represents
failure.
Use this [ ` Backoff ` ] to generate a closure that implements the backoff strategy it describes given a constructor for some kind of delay strategy parameterized by a ` Duration ` . This assumes that the [ ` default ` ] ( Default :: default ) for the given ` Strategy ` type represents failure .
pub fn build<Strategy, Error>(
        &self,
        strategy: impl Fn(Duration) -> Strategy + Sync + Send + 'static,
    ) -> impl Fn(usize, &Error) -> Strategy + Sync + Send + 'static
    where
        Strategy: Default + Sync + Send + 'static,
    {
        let initial_delay = self.initial_delay;
        let factor = self.exponent;
        let max_retries = self.max_retries;
        let jitter = self.jitter;
        let max_delay = self.max_delay;
        move |retries, _| {
            if retries <= max_retries {
                let mut delay =
                    initial_delay.mul_f64(factor.abs().powf(retries.min(max_retries) as f64));
                delay = max_delay.unwrap_or(delay).min(delay);
                let random_jitter = jitter.mul_f64(rand::random());
                if rand::random() {
                    delay += random_jitter;
                } else {
                    delay -= random_jitter.min(delay);
                }
                strategy(delay)
            } else {
                Strategy::default()
            }
        }
    }
pub fn build < Strategy , Error > ( & self , strategy : impl Fn ( Duration ) -> Strategy + Sync + Send + ' static , ) -> impl Fn ( usize , & Error ) -> Strategy + Sync + Send + ' static where Strategy : Default + Sync + Send + ' static , { let initial_delay = self . initial_delay ; let factor = self . exponent ; let max_retries = self . max_retries ; let jitter = self . jitter ; let max_delay = self . max_delay ; move | retries , _ | { if retries <= max_retries { let mut delay = initial_delay . mul_f64 ( factor . abs ( ) . powf ( retries . min ( max_retries ) as f64 ) ) ; delay = max_delay . unwrap_or ( delay ) . min ( delay ) ; let random_jitter = jitter . mul_f64 ( rand :: random ( ) ) ; if rand :: random ( ) { delay += random_jitter ; } else { delay -= random_jitter . min ( delay ) ; } strategy ( delay ) } else { Strategy :: default ( ) } } }
Use this [`Backoff`] to generate a closure that implements the backoff strategy it
describes, given a constructor for some kind of delay strategy parameterized by a
`Duration`.
Use this [ ` Backoff ` ] to generate a closure that implements the backoff strategy it describes given a constructor for some kind of delay strategy parameterized by a ` Duration ` .
&self
strategy
impl Fn(Duration) -> Strategy + Sync + Send + 'static