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)
})
}
}