Trait jsonrpc_client::SendRequest [−][src]
pub trait SendRequest: 'static where
Error<Self::Error>: From<Self::Error>, {
type Error: StdError;
fn send_request<'life0, 'async_trait, P>(
&'life0 self,
endpoint: Url,
body: String
) -> Pin<Box<dyn Future<Output = Result<Response<P>, Self::Error>> + Send + 'async_trait>>
where
P: DeserializeOwned,
P: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
}
Expand description
A trait abstracting over how a request is actually sent to a server.
This trait needs to be implemented on the “inner” client.
Example
struct MyHttpClient;
struct MyError;
#[async_trait::async_trait]
impl SendRequest for MyHttpClient {
type Error = MyError;
async fn send_request<P>(&self, endpoint: Url, body: String) -> Result<Response<P>, Self::Error>
where
P: DeserializeOwned,
{
// send the given body to the given endpoint and deserialize the response as `Response<P>`
}
}
#[jsonrpc_client::api]
pub trait Math {
async fn subtract(&self, subtrahend: i64, minuend: i64) -> i64;
}
#[jsonrpc_client::implement(Math)]
struct Client {
inner: MyHttpClient,
base_url: Url,
}