pub trait Pop<T> {
type Result;
// Required method
fn pop(self) -> (T, Self::Result);
}
Expand description
Defines a method for permanently extracting a value, changing the resulting type. Used to specify that a hyper service consumes some data from the context, making it unavailable to later layers, e.g.
struct MyItem1;
struct MyItem2;
struct MyItem3;
struct MiddlewareService<T, C> {
inner: T,
marker: PhantomData<C>,
}
impl<T, C, D, E> hyper::service::Service<(hyper::Request<hyper::Body>, C)> for MiddlewareService<T, C>
where
C: Pop<MyItem1, Result=D> + Send + 'static,
D: Pop<MyItem2, Result=E>,
E: Pop<MyItem3>,
E::Result: Send + 'static,
T: hyper::service::Service<(hyper::Request<hyper::Body>, E::Result)>
{
type Response = T::Response;
type Error = T::Error;
type Future = T::Future;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.inner.poll_ready(cx)
}
fn call(&mut self, req : (hyper::Request<hyper::Body>, C)) -> Self::Future {
let (request, context) = req;
// type annotations optional, included for illustrative purposes
let (_, context): (MyItem1, D) = context.pop();
let (_, context): (MyItem2, E) = context.pop();
let (_, context): (MyItem3, E::Result) = context.pop();
self.inner.call((request, context))
}
}