Trait Predicate

Source
pub trait Predicate<Request> {
    type Request;
    type Response;

    // Required method
    fn check(&self, request: Request) -> Result<Self::Request, Self::Response>;
}
Expand description

Checks a request synchronously

§Example

struct CheckService;

impl<ResBody, ReqBody> Predicate<Request<ReqBody>, ResBody> for CheckService
where
    ResBody: Default,
{
    type Request = Request<ReqBody>;
    type Response = Response<ResBody>;

    fn check(&mut self, mut request: Request<ReqBody>) -> Result<Self::Request, Self::Response> {
        // do something check
        Ok(request)   
    }
}

Required Associated Types§

Source

type Request

The type of requests returned by check.

This request is forwarded to the inner service if the predicate succeeds.

Source

type Response

The type of response return by check if the predicate failed.

Required Methods§

Source

fn check(&self, request: Request) -> Result<Self::Request, Self::Response>

Check whether the given request should be forwarded.

If the future resolves with Ok, the request is forwarded to the inner service.

Implementors§

Source§

impl<T, Req, Res, F> Predicate<T> for F
where F: Fn(T) -> Result<Req, Res>,

Source§

type Request = Req

Source§

type Response = Res