use crate::{load::Load, Middleware, Service, ServiceExt};
#[derive(Clone, Debug)]
pub struct Depressurize<S> {
inner: S,
}
impl<S> Depressurize<S> {
pub(crate) fn new(inner: S) -> Self {
Self { inner }
}
}
impl<Request, S> Service<Request> for Depressurize<S>
where
S: Service<Request>,
{
type Response = S::Response;
type Permit<'a> = &'a S
where
S: 'a;
async fn acquire(&self) -> Self::Permit<'_> {
&self.inner
}
async fn call(permit: Self::Permit<'_>, request: Request) -> Self::Response {
permit.oneshot(request).await
}
}
impl<S> Load for Depressurize<S>
where
S: Load,
{
type Metric = S::Metric;
fn load(&self) -> Self::Metric {
self.inner.load()
}
}
impl<S, T> Middleware<S> for Depressurize<T>
where
T: Middleware<S>,
{
type Service = Depressurize<T::Service>;
fn apply(self, svc: S) -> Self::Service {
let Self { inner } = self;
Depressurize {
inner: inner.apply(svc),
}
}
}