Trait swagger::context::Push

source ·
pub trait Push<T> {
    type Result;

    // Required method
    fn push(self, value: 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<(hyper::Request<hyper::Body>, C)> 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<(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;
        let context = context
            .push(MyItem1{})
            .push(MyItem2{})
            .push(MyItem3{});
        self.inner.call((request, context))
    }
}

Required Associated Types§

source

type Result

The type that results from adding an item.

Required Methods§

source

fn push(self, value: T) -> Self::Result

Inserts a value.

Implementors§