2020-03-31 10:10:47 -07:00
|
|
|
use super::Filter;
|
2019-03-01 15:25:21 -08:00
|
|
|
use tower_layer::Layer;
|
|
|
|
|
2019-09-23 14:28:14 -07:00
|
|
|
/// Conditionally dispatch requests to the inner service based on a predicate.
|
|
|
|
#[derive(Debug)]
|
2019-03-01 15:25:21 -08:00
|
|
|
pub struct FilterLayer<U> {
|
|
|
|
predicate: U,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<U> FilterLayer<U> {
|
2019-09-23 14:28:14 -07:00
|
|
|
#[allow(missing_docs)]
|
2019-03-01 15:25:21 -08:00
|
|
|
pub fn new(predicate: U) -> Self {
|
|
|
|
FilterLayer { predicate }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-11 13:38:45 -07:00
|
|
|
impl<U: Clone, S> Layer<S> for FilterLayer<U> {
|
2019-03-01 15:25:21 -08:00
|
|
|
type Service = Filter<S, U>;
|
|
|
|
|
2019-04-11 13:38:45 -07:00
|
|
|
fn layer(&self, service: S) -> Self::Service {
|
2019-03-01 15:25:21 -08:00
|
|
|
let predicate = self.predicate.clone();
|
2019-04-11 13:38:45 -07:00
|
|
|
Filter::new(service, predicate)
|
2019-03-01 15:25:21 -08:00
|
|
|
}
|
|
|
|
}
|