Skip to main content

Transport

Trait Transport 

Source
pub trait Transport: Send {
    // Required methods
    fn connect<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn write<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        data: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn end_input<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn read_next_message<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Value>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn close<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn is_ready(&self) -> bool;
    fn into_split(self: Box<Self>) -> TransportSplitResult;
}
Expand description

Async transport trait for bidirectional communication with the Claude Code CLI.

Implementations handle the lifecycle of the communication channel: connecting, writing JSON messages, reading responses, and closing the channel.

All methods are async and the trait requires Send for use in async runtimes.

§Splitting

After connect(), call into_split() to obtain independent reader and writer halves for concurrent I/O. Use split_with_adapter() for a lock-based fallback, or provide a native split for true concurrent I/O.

Required Methods§

Source

fn connect<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Establishes the transport connection (e.g., spawns the subprocess).

Source

fn write<'life0, 'life1, 'async_trait>( &'life0 mut self, data: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Writes a string (typically a JSON line) to the CLI’s input stream.

Source

fn end_input<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Signals that no more input will be sent (closes the input stream).

Source

fn read_next_message<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Option<Value>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reads the next JSON message from the CLI’s output stream.

Returns Ok(None) when the stream is exhausted (EOF).

Source

fn close<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Closes the transport connection and cleans up resources.

Source

fn is_ready(&self) -> bool

Returns true if the transport is connected and ready for I/O.

Source

fn into_split(self: Box<Self>) -> TransportSplitResult

Splits the transport into independent reader and writer halves.

Consumes the transport. The returned halves can be used concurrently from different tasks.

For a simple implementation, delegate to split_with_adapter(self) which wraps self in a SplitAdapter that serializes access via a mutex. Transports that can provide true concurrent I/O (like SubprocessCliTransport) should provide a native split instead.

§Returns

A tuple of (reader, writer, close_handle). The close_handle should be used to close the transport and clean up resources when done.

Implementors§