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 with_idempotency(self, idempotency: RequestIdempotency) -> Self
pub fn with_idempotency(self, idempotency: RequestIdempotency) -> Self
RPC half of the per-call idempotency override — forwards to
CratestackClient::with_idempotency, which documents the whole
mechanism.
RPC needs this more than REST does: every RPC call is
POST /rpc/{op_id}, so the method-derived default marks
everything non-idempotent, reads included. The per-op truth is
the idempotent_by_default field on the OpDescriptor the
schema macro emits (cratestack_core::OpDescriptor):
let response = rpc
.clone()
.with_idempotency(RequestIdempotency::new(OP.idempotent_by_default))
.call::<_, Output>(OP.op_id, &input)
.await?;Streamed calls (Self::call_streaming) carry the extension
too, but a partially-consumed stream cannot be replayed from the
middleware layer — leave those at the non-idempotent default
unless the middleware only retries before the first byte.
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.
Trait Implementations§
Auto Trait Implementations§
impl<C = CborCodec> !RefUnwindSafe for RpcClient<C>
impl<C = CborCodec> !UnwindSafe for RpcClient<C>
impl<C> Freeze for RpcClient<C>where
C: Freeze,
impl<C> Send for RpcClient<C>where
C: Send,
impl<C> Sync for RpcClient<C>where
C: Sync,
impl<C> Unpin for RpcClient<C>where
C: Unpin,
impl<C> UnsafeUnpin for RpcClient<C>where
C: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more