Trait swagger::context::Pop [] [src]

pub trait Pop<T> {
    type Result;
    fn pop(self) -> (T, Self::Result);
}

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::server::Service for MiddlewareService<T, C>
    where
        C: Pop<MyItem1, Result=D>,
        D: Pop<MyItem2, Result=E>,
        E: Pop<MyItem3>,
        T: hyper::server::Service<Request = (hyper::Request, E::Result)>
{
    type Request = (hyper::Request, C);
    type Response = T::Response;
    type Error = T::Error;
    type Future = T::Future;
    fn call(&self, (req, context) : Self::Request) -> Self::Future {

        // 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((req, context))
    }
}

Associated Types

The type that remains after the value has been popped.

Required Methods

Extracts a value.

Implementors