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
impl Client
Sourcepub fn connect(port: u16, key_dir: &Path) -> Result<Self, ControlError>
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.
Sourcepub fn connect_with_key(
port: u16,
key: impl Into<String>,
) -> Result<Self, ControlError>
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).
pub fn port(&self) -> u16
Sourcepub fn set_timeout(&mut self, t: Duration)
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).
Sourcepub fn request(
&mut self,
method: &str,
params: Value,
) -> Result<Reply, ControlError>
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.
Sourcepub fn call(
&mut self,
method: &str,
params: Value,
) -> Result<Value, ControlError>
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 Dispatch for Client
impl Dispatch for Client
Source§fn commands(&self) -> Vec<CommandInfo>
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).