Trait Pop

Source
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 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<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;

        // 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();

        let req = hyper::Request::from_parts(head, ContextualPayload { inner: body.inner, context });
        self.inner.call(req)
    }
}

Required Associated Types§

Source

type Result

The type that remains after the value has been popped.

Required Methods§

Source

fn pop(self) -> (T, Self::Result)

Extracts a value.

Implementors§