use super::{AsyncFilter, Filter};
use tower_layer::Layer;
#[derive(Debug, Clone)]
pub struct FilterLayer<U> {
predicate: U,
}
#[derive(Debug, Clone)]
pub struct AsyncFilterLayer<U> {
predicate: U,
}
impl<U> FilterLayer<U> {
pub const fn new(predicate: U) -> Self {
Self { predicate }
}
}
impl<U: Clone, S> Layer<S> for FilterLayer<U> {
type Service = Filter<S, U>;
fn layer(&self, service: S) -> Self::Service {
let predicate = self.predicate.clone();
Filter::new(service, predicate)
}
}
impl<U> AsyncFilterLayer<U> {
pub const fn new(predicate: U) -> Self {
Self { predicate }
}
}
impl<U: Clone, S> Layer<S> for AsyncFilterLayer<U> {
type Service = AsyncFilter<S, U>;
fn layer(&self, service: S) -> Self::Service {
let predicate = self.predicate.clone();
AsyncFilter::new(service, predicate)
}
}