pub struct Client { /* private fields */ }Expand description
A multiplexed, config-driven Thunder RPC client (SPEC-003).
Cheap to share behind an Arc; every method takes &self and calls
may run concurrently (CLT-010).
Implementations§
Source§impl Client
impl Client
Sourcepub async fn connect(
endpoint: &str,
config: Config,
) -> Result<Self, ClientError>
pub async fn connect( endpoint: &str, config: Config, ) -> Result<Self, ClientError>
Connect with default ClientConfig and run the configured
handshake (CLT-001/002).
config is the application’s protocol config (SPEC-002) — the
handshake, caps and error conventions of the thing you are dialing.
Not to be confused with ClientConfig, which is this caller’s
credentials and timeouts; see Client::connect_with.
endpoint accepts every form of parse_endpoint (CLT-070):
scheme://host[:port] or bare host:port.
Sourcepub async fn connect_with(
endpoint: &str,
config: Config,
client_config: ClientConfig,
) -> Result<Self, ClientError>
pub async fn connect_with( endpoint: &str, config: Config, client_config: ClientConfig, ) -> Result<Self, ClientError>
Connect with an explicit ClientConfig.
The two configs are different things and both are required:
config: the application’s protocol config (SPEC-002) — what the peer speaks;client_config: this caller’s credentials and timeouts.
Sourcepub async fn call(
&self,
command: impl Into<String>,
args: Vec<Value>,
) -> Result<Value, ClientError>
pub async fn call( &self, command: impl Into<String>, args: Vec<Value>, ) -> Result<Value, ClientError>
Issue one call with the client’s default timeout (CLT-020).
Concurrent callers multiplex over the one connection; completion order follows the server, not submission order (CLT-010).
Sourcepub async fn call_with_timeout(
&self,
command: &str,
args: Vec<Value>,
timeout: Duration,
) -> Result<Value, ClientError>
pub async fn call_with_timeout( &self, command: &str, args: Vec<Value>, timeout: Duration, ) -> Result<Value, ClientError>
Issue one call with a per-call timeout override (CLT-020).
Sourcepub fn on_push<F>(&self, handler: F)
pub fn on_push<F>(&self, handler: F)
Register the push hook (CLT-060). Frames with id == PUSH_ID are
routed here under PushPolicy::Enabled and never matched against
pending calls. The handler runs on the reader task.
Sourcepub async fn close(&self)
pub async fn close(&self)
Explicit, idempotent close (CLT-004): fails all in-flight calls with a typed connection-closed error and shuts the socket down.
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
true once the current connection’s handshake authenticated
(CLT-003 — auth is sticky per connection).
Sourcepub fn is_alive(&self) -> bool
pub fn is_alive(&self) -> bool
true while the current connection is live — not poisoned (CLT-014)
and not closed (CLT-004). The optional pool (CLT-080) uses this to drop
a dead connection instead of handing it back; ordinary callers rely on
typed call errors and lazy reconnect (CLT-030) rather than polling this.
Sourcepub fn capabilities(&self) -> Vec<String>
pub fn capabilities(&self) -> Vec<String>
Capabilities the server advertised in the HELLO reply.
Sourcepub fn handshake_info(&self) -> HandshakeInfo
pub fn handshake_info(&self) -> HandshakeInfo
Snapshot of what the handshake learned (CLT-002).
Sourcepub fn unknown_response_drops(&self) -> u64
pub fn unknown_response_drops(&self) -> u64
How many responses matched no pending call and were dropped (CLT-013 — client stats, never fatal).