Skip to main content

Client

Struct Client 

Source
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

Source

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.

Source

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

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

Source

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

Source

pub fn on_push<F>(&self, handler: F)
where F: Fn(Value) + Send + Sync + 'static,

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.

Source

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.

Source

pub fn is_authenticated(&self) -> bool

true once the current connection’s handshake authenticated (CLT-003 — auth is sticky per connection).

Source

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.

Source

pub fn capabilities(&self) -> Vec<String>

Capabilities the server advertised in the HELLO reply.

Source

pub fn handshake_info(&self) -> HandshakeInfo

Snapshot of what the handshake learned (CLT-002).

Source

pub fn unknown_response_drops(&self) -> u64

How many responses matched no pending call and were dropped (CLT-013 — client stats, never fatal).

Source

pub fn config(&self) -> &Config

The application’s protocol config this client drives its behavior from (SPEC-002).

Trait Implementations§

Source§

impl Debug for Client

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for Client

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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.