Skip to main content

Client

Struct Client 

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

A connection to 127.0.0.1:<port> (the control port is loopback only, so the key never leaves the machine). Reconnects when the app closed the kept connection or restarted (a restart also means a new key, read again from the key file), but only before a request was sent: once any byte of a request reached the socket it is never sent again, so a mutating command cannot run twice when the app dies mid-request.

Implementations§

Source§

impl Client

Source

pub fn connect(port: u16, key_dir: &Path) -> Result<Self, ControlError>

Connect to the app on port whose key file is in key_dir; fails fast when nothing listens or the key is refused.

Source

pub fn connect_with_key( port: u16, key: impl Into<String>, ) -> Result<Self, ControlError>

Connect with a key known in-process (tests, a parent that started the app).

Source

pub fn port(&self) -> u16

Source

pub fn set_timeout(&mut self, t: Duration)

How long to wait for one reply (default 90 s; the app itself gives up after its own reply timeout, 60 s by default).

Source

pub fn request( &mut self, method: &str, params: Value, ) -> Result<Reply, ControlError>

Send one request and return the app’s reply; Err only for transport failures.

Source

pub fn call( &mut self, method: &str, params: Value, ) -> Result<Value, ControlError>

Call one method: its result, or the app’s error as ControlError::Remote.

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 Dispatch for Client

Source§

fn commands(&self) -> Vec<CommandInfo>

The app’s commands; empty when it cannot be reached (Dispatch has no error channel here; use Client::call with engine.commands to see why).

Source§

fn execute(&mut self, id: &str, params: Value) -> Result<Value, CommandError>

Auto Trait Implementations§

§

impl Forget for Client

§

impl Freeze for Client

§

impl Move for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin for Client

§

impl UnwindSafe 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<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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.