rama_http/layer/retry/
layer.rs1use super::Retry;
2use rama_core::Layer;
3use std::fmt;
4
5pub struct RetryLayer<P> {
7 policy: P,
8}
9
10impl<P: fmt::Debug> fmt::Debug for RetryLayer<P> {
11 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12 f.debug_struct("RetryLayer")
13 .field("policy", &self.policy)
14 .finish()
15 }
16}
17
18impl<P: Clone> Clone for RetryLayer<P> {
19 fn clone(&self) -> Self {
20 Self {
21 policy: self.policy.clone(),
22 }
23 }
24}
25
26impl<P> RetryLayer<P> {
27 pub const fn new(policy: P) -> Self {
29 RetryLayer { policy }
30 }
31}
32
33impl<P, S> Layer<S> for RetryLayer<P>
34where
35 P: Clone,
36{
37 type Service = Retry<P, S>;
38
39 fn layer(&self, service: S) -> Self::Service {
40 let policy = self.policy.clone();
41 Retry::new(policy, service)
42 }
43}