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