rama_http/layer/retry/
layer.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use super::Retry;
use rama_core::Layer;
use std::fmt;

/// Retry requests based on a policy
pub struct RetryLayer<P> {
    policy: P,
}

impl<P: fmt::Debug> fmt::Debug for RetryLayer<P> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_struct("RetryLayer")
            .field("policy", &self.policy)
            .finish()
    }
}

impl<P: Clone> Clone for RetryLayer<P> {
    fn clone(&self) -> Self {
        Self {
            policy: self.policy.clone(),
        }
    }
}

impl<P> RetryLayer<P> {
    /// Creates a new [`RetryLayer`] from a retry policy.
    pub const fn new(policy: P) -> Self {
        RetryLayer { policy }
    }
}

impl<P, S> Layer<S> for RetryLayer<P>
where
    P: Clone,
{
    type Service = Retry<P, S>;

    fn layer(&self, service: S) -> Self::Service {
        let policy = self.policy.clone();
        Retry::new(policy, service)
    }
}