Skip to main content

JsonRpcClient

Struct JsonRpcClient 

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

A JSON-RPC 2.0 client that communicates over line-delimited JSON on the stdin/stdout of a child process.

Implementations§

Source§

impl JsonRpcClient

Source

pub fn new(stdin: ChildStdin, stdout: ChildStdout) -> Self

Create a new client.

Spawns a background tokio task that reads line-delimited JSON from stdout, routing responses to their pending futures and everything else (notifications / incoming RPC calls) to an mpsc channel retrievable via [take_incoming].

Source

pub fn take_incoming(&mut self) -> Option<UnboundedReceiver<IncomingMessage>>

Take the receiver for incoming notifications and RPC calls.

This can only be called once — subsequent calls return None.

Source

pub async fn request( &self, method: &str, params: Option<Value>, ) -> Result<Response, Box<dyn Error + Send + Sync>>

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

Source

pub async fn notify( &self, method: &str, params: Option<Value>, ) -> Result<(), Box<dyn Error + Send + Sync>>

Send a JSON-RPC notification (no id, no response expected).

Source

pub async fn respond( &self, id: u64, result: Option<Value>, error: Option<RpcError>, ) -> Result<(), Box<dyn Error + Send + Sync>>

Send a JSON-RPC response to an incoming RPC call from the agent.

Trait Implementations§

Source§

impl Debug for JsonRpcClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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, 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.