pub struct ControlClient { /* private fields */ }Expand description
The client half of the control transport: connects to the daemon’s control
socket (resolved from a ControlId), sends one ControlRequest, and
reads back its ControlResponse. A fresh connection per request keeps it
simple and stateless.
Implementations§
Source§impl ControlClient
impl ControlClient
Sourcepub fn new(id: impl Into<ControlId>) -> Self
pub fn new(id: impl Into<ControlId>) -> Self
A client for the control socket identified by id, with no token.
Only reaches a daemon that runs without one, which in practice means a
test driving the protocol directly. Real callers use
with_token - see ControlToken.
Sourcepub fn with_token(self, token: ControlToken) -> Self
pub fn with_token(self, token: ControlToken) -> Self
Present token on every connection this client opens.
Sourcepub fn for_home(id: impl Into<ControlId>, dir: &Path) -> Self
pub fn for_home(id: impl Into<ControlId>, dir: &Path) -> Self
A client that reads the daemon’s token out of dir.
A missing token file is not an error here. It has two very different
causes - no daemon is running, or one is running that predates tokens -
and the client cannot tell them apart, while the daemon can. Refusing to
even construct a client would make the second case unrecoverable: an
upgraded CLI could not ask the still-running pre-token daemon to shut
down, so it could neither stop it nor start a replacement, and the error
it printed (“Is the daemon running? Start it with lev daemon start”)
would be advice the user was already following.
The daemon is the enforcer. A client with no token connects, is refused if the daemon requires one, and reports that - which is accurate.
Sourcepub async fn request(&self, req: &ControlRequest) -> Result<ControlResponse>
pub async fn request(&self, req: &ControlRequest) -> Result<ControlResponse>
Send one request and await its response. Errors if the daemon can’t be
reached, does not answer within request_timeout, the connection closes
before a reply, or the reply doesn’t parse.
Sourcepub async fn spawn(&self, args: SpawnArgs) -> Result<ControlResponse>
pub async fn spawn(&self, args: SpawnArgs) -> Result<ControlResponse>
Spawn a new agent.
Sourcepub async fn status(&self, run_id: &str) -> Result<ControlResponse>
pub async fn status(&self, run_id: &str) -> Result<ControlResponse>
Query a run’s status.
Sourcepub async fn list(&self) -> Result<ControlResponse>
pub async fn list(&self) -> Result<ControlResponse>
List every known live run.
Sourcepub async fn shutdown(&self) -> Result<ControlResponse>
pub async fn shutdown(&self) -> Result<ControlResponse>
Ask the daemon to shut down.
Sourcepub async fn subscribe(&self) -> Result<WorldEventStream>
pub async fn subscribe(&self) -> Result<WorldEventStream>
Open a pushed event stream: connect, send Subscribe, and return a reader
that yields WorldEvents until the daemon closes the connection. The
HTTP/WS gateway uses this instead of polling.
Trait Implementations§
Source§impl Clone for ControlClient
impl Clone for ControlClient
Source§fn clone(&self) -> ControlClient
fn clone(&self) -> ControlClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ControlClient
impl RefUnwindSafe for ControlClient
impl Send for ControlClient
impl Sync for ControlClient
impl Unpin for ControlClient
impl UnsafeUnpin for ControlClient
impl UnwindSafe for ControlClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.