• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use super::Retry;
2 use tower_layer::Layer;
3 
4 /// Retry requests based on a policy
5 #[derive(Debug)]
6 pub struct RetryLayer<P> {
7     policy: P,
8 }
9 
10 impl<P> RetryLayer<P> {
11     /// Create a new [`RetryLayer`] from a retry policy
new(policy: P) -> Self12     pub fn new(policy: P) -> Self {
13         RetryLayer { policy }
14     }
15 }
16 
17 impl<P, S> Layer<S> for RetryLayer<P>
18 where
19     P: Clone,
20 {
21     type Service = Retry<P, S>;
22 
layer(&self, service: S) -> Self::Service23     fn layer(&self, service: S) -> Self::Service {
24         let policy = self.policy.clone();
25         Retry::new(policy, service)
26     }
27 }
28