CommandClient

Struct CommandClient 

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

High-level client that talks to Cloudflare’s host-managed command channel (Cloud Run does not expose one).

Commands are framed as JSON lines and travel over stdin/stdout (default), TCP, or Unix sockets (when enabled). Responses are deserialized back into CommandResponse instances and surfaced through async APIs.

§Transport Modes

  • stdio: bidirectional pipes that the Workers container sidecar keeps open.
  • tcp://host:port: an explicit TCP socket managed by the sidecar.
  • unix://path (Unix only): a Unix domain socket exposed by the sidecar.

§Errors

All async constructors and CommandClient::send return CommandError when the transport cannot be established, the host drops the channel, or the host reports a failure.

§Examples

use containerflare_command::{CommandClient, CommandEndpoint, CommandRequest};

let client = CommandClient::connect(CommandEndpoint::Stdio).await?;
let response = client.send(CommandRequest::empty("health_check")).await?;
assert!(response.ok);

Implementations§

Source§

impl CommandClient

Source

pub async fn connect(endpoint: CommandEndpoint) -> Result<Self, CommandError>

Connects to the configured endpoint using the default timeout.

§Parameters
  • endpoint - Transport descriptor (stdio, TCP, or Unix socket).
§Returns

A connected CommandClient ready to issue commands.

§Errors

Returns CommandError if the underlying transport cannot be opened or is closed before the connection is established.

§Panics

Does not panic.

Source

pub async fn connect_with_timeout( endpoint: CommandEndpoint, timeout: Duration, ) -> Result<Self, CommandError>

Connects to the endpoint and enforces a custom read timeout.

§Parameters
  • endpoint - Transport descriptor (stdio, TCP, or Unix socket).
  • timeout - Maximum duration to wait for each response before failing.
§Returns

A connected CommandClient that enforces the provided timeout for every command.

§Errors

Returns CommandError if the underlying transport cannot be opened or the timeout elapses while establishing the connection.

§Panics

Does not panic.

Source

pub fn unavailable(reason: impl Into<String>) -> Self

Creates a CommandClient that always reports an unavailable channel.

This is useful for runtimes (Google Cloud Run, local testing, etc.) that do not expose a host-managed command bus but still want to share the API surface.

Source

pub fn endpoint(&self) -> &CommandEndpoint

Returns the endpoint backing this client.

Source

pub async fn send( &self, request: CommandRequest, ) -> Result<CommandResponse, CommandError>

Sends a command request and waits for a response (or timeout).

§Parameters
  • request - Structured command for the Workers sidecar.
§Returns

The CommandResponse emitted by the sidecar.

§Errors

Returns CommandError if the channel closes, the response payload cannot be deserialized, the command reports a failure, or the read timeout elapses.

§Panics

Does not panic.

Trait Implementations§

Source§

impl Clone for CommandClient

Source§

fn clone(&self) -> CommandClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CommandClient

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.