pub trait Push<T> {
type Result;
// Required method
fn push(self, v: T) -> Self::Result;
}
Expand description
Defines a method for inserting a value, changing the resulting type. Used to specify that a hyper service adds some data from the context, making it available 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 for MiddlewareService<T, C>
where
C: Push<MyItem1, Result=D> + Send + 'static,
D: Push<MyItem2, Result=E>,
E: Push<MyItem3>,
E::Result: Send + 'static,
T: hyper::service::Service<ReqBody=ContextualPayload<hyper::Body, E::Result>>
{
type ReqBody = ContextualPayload<hyper::Body, C>;
type ResBody = T::ResBody;
type Error = T::Error;
type Future = T::Future;
fn call(&mut self, req : hyper::Request<Self::ReqBody>) -> Self::Future {
let (head, body) = req.into_parts();
let context = body.context
.push(MyItem1{})
.push(MyItem2{})
.push(MyItem3{});
let req = hyper::Request::from_parts(head, ContextualPayload { inner: body.inner, context });
self.inner.call(req)
}
}