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§
Required Methods§
Provided Methods§
sourcefn call<F, I, R>(&self, f: F, input: I) -> OneshotReceiver<R> ⓘ
fn call<F, I, R>(&self, f: F, input: I) -> OneshotReceiver<R> ⓘ
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);
}
sourcefn call_failable<F, I, T, E>(
&self,
f: F,
input: I,
) -> RpcResultReceiver<Result<T, E>> ⓘ
fn call_failable<F, I, T, E>( &self, f: F, input: I, ) -> RpcResultReceiver<Result<T, E>> ⓘ
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.