Skip to main content

JsonRpcClient

Struct JsonRpcClient 

Source
pub struct JsonRpcClient { /* private fields */ }
Expand description

Low-level JSON-RPC 2.0 client over Content-Length-framed streams.

§Cancel safety

All public methods (write, send_request) are cancel-safe: the actual bytes hit the wire on a dedicated background actor task, so dropping the caller’s future after await returns Pending cannot produce a partial frame on the wire. Frames either land atomically or the underlying I/O fails. See cancel-safety review artifact for the full RFD-400 reasoning.

Implementations§

Source§

impl JsonRpcClient

Source

pub fn new( writer: impl AsyncWrite + Unpin + Send + 'static, reader: impl AsyncRead + Unpin + Send + 'static, notification_tx: Sender<JsonRpcNotification>, request_tx: UnboundedSender<JsonRpcRequest>, ) -> Self

Create a new client from async read/write streams.

Spawns two background tasks: a reader that dispatches incoming messages to pending request channels, the notification broadcast, or the request-forwarding channel; and a writer actor that owns the underlying AsyncWrite and serializes frames atomically.

Source

pub async fn send_request( &self, method: &str, params: Option<Value>, ) -> Result<JsonRpcResponse, Error>

Send a JSON-RPC request and wait for the matching response.

§Cancel safety

Cancel-safe. The frame is committed to the wire via the writer actor before this future yields; cancelling the await drops the response oneshot but does not desync the transport. The pending- requests map is cleaned up automatically (the PendingGuard drop removes the entry, and the read loop’s response handling tolerates a missing entry).

Source

pub async fn write<T: Serialize>(&self, message: &T) -> Result<(), Error>

Write a Content-Length-framed JSON-RPC message to the transport.

§Cancel safety

Cancel-safe. Pre-serializes the body, enqueues it on the writer actor’s command channel, and awaits an ack. Caller cancellation drops the ack receiver; the actor still completes the frame and flushes. A partial frame can never appear on the wire.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more