pub trait RpcSend: Sized {
type Message;
// Required method
fn send_rpc(self, message: Self::Message);
// Provided methods
fn call<F, I, R>(self, f: F, input: I) -> PendingRpc<R> ⓘ
where F: FnOnce(Rpc<I, R>) -> Self::Message,
R: 'static + Send { ... }
fn call_failable<F, I, T, E>(
self,
f: F,
input: I,
) -> PendingFailableRpc<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) -> PendingRpc<R> ⓘ
fn call<F, I, R>(self, f: F, input: I) -> PendingRpc<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) -> PendingFailableRpc<T, E> ⓘ
fn call_failable<F, I, T, E>(self, f: F, input: I) -> PendingFailableRpc<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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.