client/
client.rs

1//! Client using macros.
2//!
3//! Run the `server-macros` example first, then run this:
4//!
5//! ```command
6//! $ cargo run --features=client --example client
7//! ```
8
9use anyhow::Result;
10use jsonrpc_utils::{rpc_client, HttpClient};
11
12struct MyRpcClient {
13    inner: HttpClient,
14}
15
16#[rpc_client]
17impl MyRpcClient {
18    async fn sleep(&self, secs: u64) -> Result<u64>;
19    async fn value(&self) -> Result<u64>;
20    async fn add(&self, (x, y): (i32, i32), z: i32) -> Result<i32>;
21    #[rpc(name = "@ping")]
22    async fn ping(&self) -> Result<String>;
23}
24
25#[tokio::main]
26pub async fn main() {
27    let client = MyRpcClient {
28        inner: HttpClient::new("http://127.0.0.1:3000/rpc".into()),
29    };
30    dbg!(client.sleep(1).await.unwrap());
31    dbg!(client.value().await.unwrap());
32    dbg!(client.add((3, 4), 5).await.unwrap());
33    dbg!(client.ping().await.unwrap());
34}