trait_net/
client.rs

1use crate::retry::Policy as RetryPolicy;
2use std::future::Future;
3
4pub trait ExecuteQuery<Request> {
5    type Response;
6
7    fn query(&self, request: Request) -> impl Future<Output = Self::Response> + Send;
8
9    fn query_with_retry(&self, request: Request) -> impl Future<Output = Self::Response> + Send
10    where
11        Request: Clone,
12        Self::Response: Send;
13
14    fn query_with_policy<Policy>(
15        &self,
16        request: Request,
17        policy: Policy,
18    ) -> impl Future<Output = Self::Response> + Send
19    where
20        Request: Clone + Send,
21        Policy: RetryPolicy<Self::Response> + Send,
22        Self::Response: Send,
23        Self: Sync,
24    {
25        async move { policy.retry(|req| self.query(req), (request,)).await }
26    }
27}