Trait AsyncPredicate

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

    // Required method
    fn check(&self, request: R) -> 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

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.

Source

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

The future returned by check

Required Methods§

Source

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

Check whether the given request should be forwarded.

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

Implementations on Foreign Types§

Source§

impl<T, R> AsyncPredicate<R> for Arc<T>
where T: AsyncPredicate<R>,

Source§

type Request = <T as AsyncPredicate<R>>::Request

Source§

type Response = <T as AsyncPredicate<R>>::Response

Source§

type Future = <T as AsyncPredicate<R>>::Future

Source§

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

Implementors§

Source§

impl<T, Req, Res, U, F> AsyncPredicate<T> for F
where F: Fn(T) -> U, U: Future<Output = Result<Req, Res>>,

Source§

type Request = Req

Source§

type Response = Res

Source§

type Future = U