blocking_client/
blocking-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, BlockingHttpClient};
11
12struct MyRpcClient {
13    inner: BlockingHttpClient,
14}
15
16#[rpc_client]
17impl MyRpcClient {
18    fn sleep(&self, secs: u64) -> Result<u64>;
19    fn add(&self, (x, y): (i32, i32), z: i32) -> Result<i32>;
20    #[rpc(name = "@ping")]
21    fn ping(&self) -> Result<String>;
22}
23
24pub fn main() {
25    let client = MyRpcClient {
26        inner: BlockingHttpClient::new("http://127.0.0.1:3000/rpc".into()),
27    };
28    dbg!(client.sleep(1).unwrap());
29    dbg!(client.add((3, 4), 5).unwrap());
30    dbg!(client.ping().unwrap());
31}