Trait TryRpcSend
pub trait TryRpcSend: Sized {
type Message;
type Error;
// Required method
fn try_send_rpc(self, message: Self::Message) -> Result<(), Self::Error>;
// Provided methods
fn try_call<F, I, R>(
self,
f: F,
input: I,
) -> Result<PendingRpc<R>, Self::Error>
where F: FnOnce(Rpc<I, R>) -> Self::Message,
R: 'static + Send { ... }
fn try_call_failable<F, I, T, E>(
self,
f: F,
input: I,
) -> Result<PendingFailableRpc<T, E>, Self::Error>
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 try to send RPC requests but may fail.
Required Associated Types§
type Message
type Message
The message type for this sender.
type Error
type Error
The error type returned when sending an RPC request fails.
Required Methods§
fn try_send_rpc(self, message: Self::Message) -> Result<(), Self::Error>
fn try_send_rpc(self, message: Self::Message) -> Result<(), Self::Error>
Tries to send an RPC request.
Provided Methods§
fn try_call<F, I, R>(self, f: F, input: I) -> Result<PendingRpc<R>, Self::Error>
fn try_call<F, I, R>(self, f: F, input: I) -> Result<PendingRpc<R>, Self::Error>
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);
}
fn try_call_failable<F, I, T, E>(
self,
f: F,
input: I,
) -> Result<PendingFailableRpc<T, E>, Self::Error>
fn try_call_failable<F, I, T, E>( self, f: F, input: I, ) -> Result<PendingFailableRpc<T, E>, Self::Error>
Issues a request and returns an object to receive the result.
This is like TryRpcSend::try_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.