use crate::{CallBuf, ProgVers, RpcError, RpcResponse};
use async_trait::async_trait;
#[async_trait]
pub trait RpcSender: Send + Sync {
fn call_buf(&self) -> CallBuf;
async fn send_call(
&self,
progvers: ProgVers,
proc: u32,
call: CallBuf,
) -> Result<RpcResponse, RpcError>;
async unsafe fn send_call_decoded(
&self,
progvers: ProgVers,
proc: u32,
call: CallBuf,
decode: &mut (dyn for<'reply> FnMut(&'reply [u8]) -> Result<(), RpcError> + Send),
) -> Result<(), RpcError> {
let response = self.send_call(progvers, proc, call).await?;
decode(&response)
}
async fn send_fire_and_forget(
&self,
progvers: ProgVers,
proc: u32,
call: CallBuf,
) -> Result<(), RpcError> {
self.send_call(progvers, proc, call).await.map(|_| ())
}
}