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§
Sourcefn connect<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
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).
Sourcefn 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 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.
Sourcefn 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 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).
Sourcefn 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 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).
Sourcefn close<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + 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,
Closes the transport connection and cleans up resources.
Sourcefn into_split(self: Box<Self>) -> TransportSplitResult
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.