Trait AsyncPredicate

Source
pub trait AsyncPredicate<Request> {
    type Request;
    type Response;
    type Future: Future<Output = Result<Self::Request, Self::Response>>;

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

Checks a request asynchronously

§Example

struct CheckService;

impl<ReqBody, ResBody> AsyncPredicate<Request<ReqBody>, ResBody> for CheckService
where
    ReqBody: Send + 'static,
    ResBody: Default + Send + 'static,
{
    type Request = Request<ReqBody>;
    type Response = Response<ResBody>;
    type Future = Pin<Box<dyn Future<Output = Result<Self::Request, Self::Response>> + Send>>;

    fn check(&mut self, request: Request<ReqBody>) -> Self::Future {
        Box::pin(async move {
            // do something check
            Ok(request)
        })
    }
}

Required Associated Types§

Source

type Request

The type of requests returned by check

Thies 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.

Source

type Future: Future<Output = Result<Self::Request, Self::Response>>

The future returned by check

Required Methods§

Source

fn check(&mut self, request: Request) -> Self::Future

Check whether the given request should be forwarded.

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

Implementors§