pub struct RpcClientHandle { /* private fields */ }Expand description
Handle for the client’s background task.
Implementations§
Source§impl RpcClientHandle
impl RpcClientHandle
Sourcepub async fn join(self) -> Result<(), JoinError>
pub async fn join(self) -> Result<(), JoinError>
Wait for the receive task to finish without aborting it.
Examples found in repository?
examples/rpc_client_server.rs (line 125)
84async fn run_client() -> Result<(), Box<dyn std::error::Error>> {
85 println!("[Client] Connecting to RPC server");
86
87 let transport = SharedMemoryFrameTransport::connect_client(SERVICE_NAME)?;
88 let channel = MessageChannelAdapter::new(transport);
89
90 let client = RpcClient::new(channel);
91 let handle = client.try_start()?;
92
93 println!("[Client] Connected!\n");
94
95 println!("[Client] Calling add(10, 32)");
96 let resp: AddResponse = client.call("add", &AddRequest { a: 10, b: 32 }).await?;
97 println!("[Client] Result: {}\n", resp.result);
98
99 println!("[Client] Calling add(100, 200)");
100 let resp: AddResponse = client.call("add", &AddRequest { a: 100, b: 200 }).await?;
101 println!("[Client] Result: {}\n", resp.result);
102
103 println!("[Client] Calling echo(\"Hello, RPC!\")");
104 let resp: EchoResponse = client
105 .call(
106 "echo",
107 &EchoRequest {
108 message: "Hello, RPC!".to_string(),
109 },
110 )
111 .await?;
112 println!(
113 "[Client] Result: message=\"{}\", length={}\n",
114 resp.message, resp.length
115 );
116
117 println!("[Client] Calling unknown method");
118 let result: Result<(), _> = client.call("unknown", &()).await;
119 match result {
120 Ok(_) => println!("[Client] Unexpected success"),
121 Err(e) => println!("[Client] Got expected error: {}\n", e),
122 }
123
124 let close_result = client.close().await;
125 let join_result = handle.join().await;
126 close_result?;
127 join_result?;
128 println!("[Client] Done!");
129
130 Ok(())
131}Auto Trait Implementations§
impl Freeze for RpcClientHandle
impl RefUnwindSafe for RpcClientHandle
impl Send for RpcClientHandle
impl Sync for RpcClientHandle
impl Unpin for RpcClientHandle
impl UnsafeUnpin for RpcClientHandle
impl UnwindSafe for RpcClientHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more