Skip to main content

StdioTransport

Struct StdioTransport 

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

Generic JSON-RPC-over-stdio transport for local subprocess agents.

Wraps a child process and provides:

The child process is killed when this struct is dropped.

Implementations§

Source§

impl StdioTransport

Source

pub fn from_child( child: Child, stdin: ChildStdin, stdout: ChildStdout, stderr: ChildStderr, rpc_timeout: Duration, ) -> Self

Wire up transport from a spawned subprocess’s stdin/stdout/stderr.

Spawns background tasks for the writer (stdin), stderr logger, and the reader (stdout) that dispatches JSON-RPC messages.

Source

pub fn new_for_testing( write_tx: UnboundedSender<String>, rpc_timeout: Duration, ) -> Self

Construct a transport with a pre-wired channel for unit tests.

No subprocess is spawned and no background tasks are started. The caller can drive the mock by reading from the paired receiver.

Source

pub fn set_notification_handler( &self, handler: Arc<dyn Fn(Value) -> Result<()> + Send + Sync>, )

Register a handler for incoming server→client requests and notifications.

Must be called once after construction. Subsequent calls overwrite the previous handler. The handler receives the raw JSON message value for every incoming message that is not a response to a pending call.

Source

pub async fn call(&self, method: &str, params: Value) -> AcpResult<Value>

Send a JSON-RPC request and wait for its response.

Assigns a monotonically increasing id, inserts it into the pending table, serialises the message, and awaits the reply up to rpc_timeout.

§Errors

Returns AcpError::Timeout if the peer does not reply in time, or AcpError::Internal if the transport is shut down.

Source

pub fn notify(&self, method: &str, params: Value) -> AcpResult<()>

Send a JSON-RPC notification (no response expected).

§Errors

Returns an error if serialisation fails or the writer task has shut down.

Source

pub fn respond(&self, id: i64, result: Value) -> AcpResult<()>

Send a JSON-RPC success response to an incoming server request.

Use this to reply to messages received by the notification handler when they carry an id field (i.e. they expect a response).

§Errors

Returns an error if serialisation fails or the writer task has shut down.

Source

pub fn respond_error( &self, id: i64, code: i32, message: impl Into<String>, ) -> AcpResult<()>

Send a JSON-RPC error response to an incoming server request.

§Errors

Returns an error if serialisation fails or the writer task has shut down.

Trait Implementations§

Source§

impl Debug for StdioTransport

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for StdioTransport

Source§

fn drop(&mut self)

Executes the destructor for this type. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoMaybeUndefined<T> for T

Source§

impl<T> IntoOption<T> for T

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more