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,
impl<B, W> Client<B, W>where
B: JsonRpcCodec,
W: WsCodec,
pub(super) async fn http_call<T: Serialize + DeserializeOwned>( &self, http_backend: &HttpClientBackend, method: &str, params: T, ) -> Result<Response>
Sourcepub(super) async fn h3_subscribe<T: Serialize + DeserializeOwned>(
self: &Arc<Self>,
http_backend: &HttpClientBackend,
method: &str,
params: T,
) -> Result<Arc<Subscription>>
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.
Sourcepub(super) async fn h3_unsubscribe(
&self,
http_backend: &HttpClientBackend,
method: &str,
sub_id: SubscriptionID,
) -> Result<()>
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,
impl<B, W> Client<B, W>where
B: JsonRpcCodec,
W: WsCodec,
Sourcepub async fn call<T: Serialize + DeserializeOwned, V: DeserializeOwned>(
&self,
method: &str,
params: T,
) -> Result<V>
pub async fn call<T: Serialize + DeserializeOwned, V: DeserializeOwned>( &self, method: &str, params: T, ) -> Result<V>
Call a method, wait for response.
Sourcepub async fn subscribe<T: Serialize + DeserializeOwned>(
self: &Arc<Self>,
method: &str,
params: T,
) -> Result<Arc<Subscription>>
pub async fn subscribe<T: Serialize + DeserializeOwned>( self: &Arc<Self>, method: &str, params: T, ) -> Result<Arc<Subscription>>
Subscribe to a method.
Sourcepub async fn unsubscribe(
&self,
method: &str,
sub_id: SubscriptionID,
) -> Result<()>
pub async fn unsubscribe( &self, method: &str, sub_id: SubscriptionID, ) -> Result<()>
Unsubscribe.
Sourcepub(crate) async fn init(
config: ClientConfig,
byte_codec: B,
ws_codec: W,
executor: Option<Executor>,
) -> Result<Arc<Self>>
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.
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>
impl<B, W> Sync for Client<B, W>
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> 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
Mutably borrows from an owned value. Read more