use http::Request;
use std::marker::PhantomData;
use futures::future::FutureExt as _;
#[derive(Debug)]
pub struct DropContextMakeService<T, C>
where
C: Send + 'static,
{
inner: T,
marker: PhantomData<C>,
}
impl<T, C> DropContextMakeService<T, C>
where
C: Send + 'static,
{
pub fn new(inner: T) -> Self {
Self {
inner,
marker: PhantomData,
}
}
}
impl<Inner, Context, Target> hyper::service::Service<Target>
for DropContextMakeService<Inner, Context>
where
Context: Send + 'static,
Inner: hyper::service::Service<Target>,
Inner::Future: Send + 'static,
{
type Response = DropContextService<Inner::Response, Context>;
type Error = Inner::Error;
type Future = futures::future::BoxFuture<'static, Result<Self::Response, Self::Error>>;
fn call(&self, target: Target) -> Self::Future {
Box::pin(
self.inner
.call(target)
.map(|s| Ok(DropContextService::new(s?))),
)
}
}
#[derive(Debug, Clone)]
pub struct DropContextService<T, C>
where
C: Send + 'static,
{
inner: T,
marker: PhantomData<C>,
}
impl<T, C> DropContextService<T, C>
where
C: Send + 'static,
{
pub fn new(inner: T) -> Self {
Self {
inner,
marker: PhantomData,
}
}
}
impl<Inner, Body, Context> hyper::service::Service<(Request<Body>, Context)>
for DropContextService<Inner, Context>
where
Context: Send + 'static,
Inner: hyper::service::Service<Request<Body>>,
{
type Response = Inner::Response;
type Error = Inner::Error;
type Future = Inner::Future;
fn call(&self, (req, _): (Request<Body>, Context)) -> Self::Future {
self.inner.call(req)
}
}