Trait mesh::rpc::RpcSend

source ·
pub trait RpcSend {
    type Message;

    // Required method
    fn send_rpc(&self, message: Self::Message);

    // Provided methods
    fn call<F, I, R>(&self, f: F, input: I) -> OneshotReceiver<R> 
       where F: FnOnce(Rpc<I, R>) -> Self::Message,
             R: 'static + Send { ... }
    fn call_failable<F, I, T, E>(
        &self,
        f: F,
        input: I,
    ) -> RpcResultReceiver<Result<T, E>> 
       where F: FnOnce(Rpc<I, Result<T, E>>) -> Self::Message,
             T: 'static + Send,
             E: 'static + Send { ... }
}
Expand description

A trait implemented by objects that can send RPC requests.

Required Associated Types§

source

type Message

The message type for this sender.

Required Methods§

source

fn send_rpc(&self, message: Self::Message)

Send an RPC request.

Provided Methods§

source

fn call<F, I, R>(&self, f: F, input: I) -> OneshotReceiver<R>
where F: FnOnce(Rpc<I, R>) -> Self::Message, R: 'static + Send,

Issues a request and returns a channel to receive the result.

f maps an Rpc object to the message type and is often an enum variant name.

input is the input to the call.

§Example
enum Request {
    Add(Rpc<(u32, u32), u32>),
}
async fn add(send: &Sender<Request>) {
    assert_eq!(send.call(Request::Add, (3, 4)).await.unwrap(), 7);
}
source

fn call_failable<F, I, T, E>( &self, f: F, input: I, ) -> RpcResultReceiver<Result<T, E>>
where F: FnOnce(Rpc<I, Result<T, E>>) -> Self::Message, T: 'static + Send, E: 'static + Send,

Issues a request and returns an object to receive the result.

This is like RpcSend::call, but for RPCs that return a Result. The returned object combines the channel error and the call’s error into a single RpcError type, which makes it easier to handle errors.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T> RpcSend for &T
where T: RpcSend,

source§

type Message = <T as RpcSend>::Message

source§

fn send_rpc(&self, message: <T as RpcSend>::Message)

Implementors§

source§

impl<T> RpcSend for MpscSender<T>
where T: 'static + Send,

source§

impl<T> RpcSend for Sender<T>
where T: 'static + Send,