use crate::ContextualPayload;
use hyper::{Body, Request};
use std::marker::PhantomData;
use std::task::{Context, Poll};
#[derive(Debug)]
pub struct DropContextMakeService<C> {
phantom: PhantomData<C>,
}
impl<C> DropContextMakeService<C> {
pub fn new() -> Self {
DropContextMakeService {
phantom: PhantomData,
}
}
}
impl<T, C> hyper::service::Service<T> for DropContextMakeService<C> {
type Response = DropContextService<T, C>;
type Error = std::io::Error;
type Future = futures::future::Ready<Result<Self::Response, Self::Error>>;
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<std::result::Result<(), Self::Error>> {
Ok(()).into()
}
fn call(&mut self, inner: T) -> Self::Future {
futures::future::ok(DropContextService::new(inner))
}
}
#[derive(Debug)]
pub struct DropContextService<T, C> {
inner: T,
marker: PhantomData<C>,
}
impl<T, C> DropContextService<T, C> {
pub fn new(inner: T) -> Self {
DropContextService {
inner,
marker: PhantomData,
}
}
}
impl<T, C> hyper::service::Service<ContextualPayload<C>> for DropContextService<T, C>
where
C: Send + Sync + 'static,
T: hyper::service::Service<Request<Body>>,
{
type Response = T::Response;
type Error = T::Error;
type Future = T::Future;
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Ok(()).into()
}
fn call(&mut self, req: ContextualPayload<C>) -> Self::Future {
self.inner.call(req.inner)
}
}