pub struct RpcClient<C = CborCodec> { /* private fields */ }Expand description
Thin RPC client built on top of the REST client’s transport + codec plumbing.
Shares a reqwest::Client and a codec impl with CratestackClient,
but speaks the /rpc/... URL space instead of REST routes. Both
clients can be used side-by-side against the same server.
Implementations§
Source§impl<C> RpcClient<C>where
C: HttpClientCodec + Clone,
impl<C> RpcClient<C>where
C: HttpClientCodec + Clone,
Sourcepub fn new(inner: CratestackClient<C>) -> Self
pub fn new(inner: CratestackClient<C>) -> Self
Build an RPC client on top of an existing REST client. The two
share their reqwest::Client, codec, and state store.
Sourcepub fn inner(&self) -> &CratestackClient<C>
pub fn inner(&self) -> &CratestackClient<C>
Underlying REST client. Exposed for callers that want REST + RPC side-by-side (e.g. a long migration window between the two).
Sourcepub fn batch_builder(&self) -> BatchBuilder<C>
pub fn batch_builder(&self) -> BatchBuilder<C>
Start a new typed batch. Use with [BatchableCall::queue] from
the macro-generated typed methods (or any hand-built
[BatchableCall]) to compose a heterogeneous batch, then
batch.send().await for a single POST /rpc/batch round-trip.
Sourcepub async fn call<I, O>(
&self,
op_id: &str,
input: &I,
) -> Result<O, RpcClientError>where
I: Serialize,
O: DeserializeOwned,
pub async fn call<I, O>(
&self,
op_id: &str,
input: &I,
) -> Result<O, RpcClientError>where
I: Serialize,
O: DeserializeOwned,
POST /rpc/{op_id} — unary call.
op_id is the dotted dispatch key the server emits — model.X.list
/ model.X.get / model.X.create / model.X.update /
model.X.delete for CRUD verbs and procedure.<name> for procedures.
Sourcepub async fn batch(
&self,
requests: &[RpcRequest],
) -> Result<Vec<RpcResponseFrame>, RpcClientError>
pub async fn batch( &self, requests: &[RpcRequest], ) -> Result<Vec<RpcResponseFrame>, RpcClientError>
POST /rpc/batch — sequence of RpcRequest frames in, sequence of
RpcResponseFrame frames out. Per-frame errors do not poison the
batch (each frame’s output / error is reported independently).
Sourcepub async fn call_streaming<I, O>(
&self,
op_id: &str,
input: &I,
) -> Result<Receiver<Result<O, RpcClientError>>, RpcClientError>
pub async fn call_streaming<I, O>( &self, op_id: &str, input: &I, ) -> Result<Receiver<Result<O, RpcClientError>>, RpcClientError>
POST /rpc/{op_id} — sequence response, item-at-a-time.
Returns a bounded mpsc::Receiver that yields each cbor-seq
item as bytes arrive over the network — no full-body buffering
before the first item reaches the caller. Transport / decode
failures appear as terminal Err items on the channel; the
receiver returning None indicates a clean stream close.
Non-2xx responses are buffered and surfaced as a single
RpcClientError::Remote(RpcRemoteError { ... }) from this
function (the channel is never opened) — same shape as the
unary call path. The server must return application/cbor-seq
for streaming; on a buffered application/cbor response this
method will misframe the body.