Struct Client

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

A JSON-RPC client.

Create a new Client using one of the transport-specific constructors:

Implementations§

Source§

impl Client

Source

pub fn with_transport<T: Transport>(transport: T) -> Client

Creates a new client with the given transport.

Source

pub fn build_request<'a>( &self, method: &'a str, params: &'a [Box<RawValue>], ) -> Request<'a>

Builds a request.

To construct the arguments, one can use one of the shorthand methods [jsonrpc::arg] or [jsonrpc::try_arg].

Source

pub async fn send_request( &self, request: Request<'_>, ) -> Result<Response, Error>

Sends a request to a client

Source

pub async fn send_batch( &self, requests: &[Request<'_>], ) -> Result<Vec<Option<Response>>, Error>

Sends a batch of requests to the client. The return vector holds the response for the request at the corresponding index. If no response was provided, it’s None.

Note that the requests need to have valid IDs, so it is advised to create the requests with [build_request].

Source

pub async fn call<R: for<'a> Deserialize<'a>>( &self, method: &str, args: &[Box<RawValue>], ) -> Result<R, Error>

Make a request and deserialize the response.

To construct the arguments, one can use one of the shorthand methods [jsonrpc::arg] or [jsonrpc::try_arg].

Source§

impl Client

Source

pub async fn simple_http( url: &str, user: Option<String>, pass: Option<String>, ) -> Result<Client, Error>

Create a new JSON-RPC client using a bare-minimum HTTP transport.

Trait Implementations§

Source§

impl Debug for Client

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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.