rpc_call

Macro rpc_call 

Source
macro_rules! rpc_call {
    (sender: $sender:expr, to_send: $to_send:expr, receiver: $received:pat_param => $to_do:block,) => { ... };
}
Expand description

Invokes an RPC call within the current async runtime.

§Params

  • sender: A reference to an IpcRpcServer, IpcRpcClient, or IpcRpc
  • to_send: The message sent to the remote
  • receiver: The expected response pattern, followed by a handler for it.

§Returns

The value returned by receiver.

§Panics

Panics if the message received from the remote doesn’t match the pattern specified in receiver.

§Example

use serde::{Deserialize, Serialize};
use schemars::JsonSchema;
use std::fmt::Debug;

#[derive(Deserialize, Serialize, Debug, Clone, JsonSchema)]
enum Message {
    MakeMeASandwich,
    /// The sandwiches are made of i32 around here, don't judge.
    ASandwich(Vec<i32>),
}

// Initialize a client

rpc_call!(
    sender: client,
    to_send: Message::MakeMeASandwich,
    receiver: Message::ASandwich(parts) => {
        log::info!("I got a sandwich! It contains\n{parts:#?}");
    },
)
.unwrap()