Skip to main content

Client

Struct Client 

Source
pub struct Client<B = JsonCodec, W = JsonCodec> {
    pub(crate) disconnect: AtomicBool,
    pub(crate) task_group: Arc<TaskGroup>,
    pub(crate) config: ClientConfig,
    pub(crate) backend: ClientBackend,
    _codecs: PhantomData<(B, W)>,
}
Expand description

An RPC client that connects to a JSON-RPC 2.0 server.

B is the byte-stream codec used for TCP/TLS/Unix/QUIC/HTTP. W is the WebSocket codec used for ws:// / wss://. Both default to JsonCodec.

Fields§

§disconnect: AtomicBool§task_group: Arc<TaskGroup>§config: ClientConfig§backend: ClientBackend§_codecs: PhantomData<(B, W)>

Implementations§

Source§

impl<B, W> Client<B, W>
where B: JsonRpcCodec, W: WsCodec,

Source

pub(super) async fn http_call<T: Serialize + DeserializeOwned>( &self, http_backend: &HttpClientBackend, method: &str, params: T, ) -> Result<Response>

Source

pub(super) async fn h3_subscribe<T: Serialize + DeserializeOwned>( self: &Arc<Self>, http_backend: &HttpClientBackend, method: &str, params: T, ) -> Result<Arc<Subscription>>

Subscribe over HTTP/3.

Source

pub(super) async fn h3_unsubscribe( &self, http_backend: &HttpClientBackend, method: &str, sub_id: SubscriptionID, ) -> Result<()>

Unsubscribe over HTTP/3.

Source§

impl<B, W> Client<B, W>
where B: JsonRpcCodec, W: WsCodec,

Source

pub async fn call<T: Serialize + DeserializeOwned, V: DeserializeOwned>( &self, method: &str, params: T, ) -> Result<V>

Call a method, wait for response.

Source

pub async fn subscribe<T: Serialize + DeserializeOwned>( self: &Arc<Self>, method: &str, params: T, ) -> Result<Arc<Subscription>>

Subscribe to a method.

Source

pub async fn unsubscribe( &self, method: &str, sub_id: SubscriptionID, ) -> Result<()>

Unsubscribe.

Source

pub async fn stop(&self)

Disconnect the client.

Source

pub(crate) async fn init( config: ClientConfig, byte_codec: B, ws_codec: W, executor: Option<Executor>, ) -> Result<Arc<Self>>

Pick the right backend based on endpoint kind, then build the Client. Each backend module returns just the ClientBackend; assembly happens here. Multiplexed mode also needs an extra step to start its background reader/writer loop.

Source

fn with_backend( config: ClientConfig, task_group: Arc<TaskGroup>, backend: ClientBackend, ) -> Arc<Self>

Auto Trait Implementations§

§

impl<B = JsonCodec, W = JsonCodec> !Freeze for Client<B, W>

§

impl<B = JsonCodec, W = JsonCodec> !RefUnwindSafe for Client<B, W>

§

impl<B, W> Send for Client<B, W>
where B: Send, W: Send,

§

impl<B, W> Sync for Client<B, W>
where B: Sync, W: Sync,

§

impl<B = JsonCodec, W = JsonCodec> !Unpin for Client<B, W>

§

impl<B = JsonCodec, W = JsonCodec> !UnsafeUnpin for Client<B, W>

§

impl<B = JsonCodec, W = JsonCodec> !UnwindSafe for Client<B, W>

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.

§

impl<T> Instrument for T

§

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

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

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> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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