Skip to main content

Client

Struct Client 

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

A connection to a host.

Async because the transport is. A caller that wants blocking behavior runs it on a runtime it owns; the crate does not choose one on its behalf.

Implementations§

Source§

impl Client

Source

pub async fn connect(address: &str) -> Result<Self, Error>

Connects to a host.

address is a websocket URL, such as ws://127.0.0.1:50751.

§Errors

Error::Transport if the connection or handshake fails.

Source

pub async fn connect_with_backoff( address: &str, backoff: Backoff, ) -> Result<Self, Error>

Connects, retrying while the host is unreachable.

For a panel meant to survive a host restart. Returns the last failure once the attempts run out, rather than looping for ever, so a caller still learns that the host is gone.

§Errors

Error::Transport carrying the final failure.

Source

pub async fn send(&mut self, command: &Command) -> Result<(), Error>

Sends one command.

§Errors

Error::Payload if the command cannot be encoded, or Error::Transport if the socket refuses it.

Source

pub async fn next(&mut self) -> Result<Option<Inbound>, Error>

Reads the next acknowledgement or event.

Returns None once the host closes the connection. Frames that are not text are skipped, so a ping or a pong does not look like an answer.

§Errors

Error::Transport if the socket fails, or Error::Payload if a text frame is neither shape.

Source

pub async fn close(self, observe: impl FnMut(Inbound)) -> Result<(), Error>

Starts a close, then reads until the peer closes back.

RFC 6455 section 5.5.1 makes closing a handshake rather than a hang-up: each side sends a Close and waits for the other. Dropping the socket without it leaves the peer to time out.

No data frame goes out after the Close, which the same section forbids. This only reads from that point on.

Messages arriving before the peer’s Close are handed to observe, since a run can still be reporting when a client decides to leave.

§Errors

Error::Transport if the Close cannot be sent.

Source

pub async fn ping(&mut self, payload: Vec<u8>) -> Result<(), Error>

Sends a ping carrying payload.

RFC 6455 section 5.5.2: an endpoint receiving a Ping MUST answer with a Pong, unless it has already received a Close. The section names this use directly, as a keepalive or a way to check the peer still responds, which is what a connection count alone cannot tell you.

The pong is consumed by the library rather than surfaced here, so this proves liveness by the absence of a transport error rather than by a returned value.

A payload over MAX_CONTROL_PAYLOAD is refused here. Section 5.5 caps every control frame at 125 bytes, and measured against a live peer an oversized ping is not rejected on the way out: the send reports success and the connection is then torn down, so the caller is told the ping worked and loses the session. Refusing before the send turns a silent kill into an error the caller can act on.

§Errors

Error::ControlFrameTooLarge if the payload exceeds the cap, or Error::Transport if the ping cannot be sent.

Source

pub async fn request( &mut self, command: &Command, observe: impl FnMut(&MessageEvent), ) -> Result<Ack, Error>

Sends a command and reads until its acknowledgement arrives.

Events that arrive first are handed to observe rather than dropped, because a run reports progress while a command is in flight and a caller that discards those loses the trace.

§Errors

Error if the send fails, the socket fails, or the host closes before answering.

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 !UnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

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

Source§

fn vzip(self) -> V