pub trait SendRequest: 'static{
type Error: StdError;
// Required method
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 + 'async_trait,
Self: 'async_trait,
'life0: '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,
}Required Associated Types§
Required Methods§
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 + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.