Skip to main content

InMemoryWireClient

Struct InMemoryWireClient 

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

In-memory wire client for unit tests.

Holds an internal queue of crate::protocol::RawWireMessages that read_raw_message drains. Tests inject messages via InMemoryWireClient::inject.

Implementations§

Source§

impl InMemoryWireClient

Source

pub fn new() -> Self

Create a new in-memory client.

Source

pub fn with_default_timeout(self, timeout: Duration) -> Self

Set a default timeout applied to every read_response call. Without this, read_response waits indefinitely for a matching id.

Source

pub async fn inject(&self, msg: RawWireMessage)

Inject an incoming raw wire message for the client to read.

Source

pub async fn outgoing(&self) -> Vec<Value>

Access all messages sent by the client.

Trait Implementations§

Source§

impl Debug for InMemoryWireClient

Source§

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

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

impl Default for InMemoryWireClient

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl WireClient for InMemoryWireClient

Source§

fn next_id(&mut self) -> String

Generate the next request id.
Source§

async fn send_request<Params: Serialize + Sync>( &mut self, req: &JsonRpcRequest<Params>, ) -> Result<(), WireError>

Send a JSON-RPC request.
Source§

async fn read_raw_message(&mut self) -> Result<RawWireMessage, WireError>

Read the next incoming raw wire message.
Source§

async fn read_raw_message_timeout( &mut self, timeout: Duration, ) -> Result<RawWireMessage, WireError>

Read the next incoming raw wire message with a timeout.
Source§

async fn read_response<T: DeserializeOwned + Send>( &mut self, expected_id: &str, ) -> Result<T, WireError>

Wait for a response matching expected_id, buffering out-of-order messages internally.
Source§

async fn send_response<T: Serialize + Send>( &mut self, id: &str, result: T, ) -> Result<(), WireError>

Send a JSON-RPC success response.
Source§

async fn send_error( &mut self, id: &str, code: i32, message: &str, ) -> Result<(), WireError>

Send a JSON-RPC error response.
Source§

async fn initialize( &mut self, _params: InitializeParams, ) -> Result<InitializeResult, WireError>

Perform the initialize handshake.
Source§

fn is_handshake_done(&self) -> bool

Returns true if the initialize handshake has completed.
Source§

async fn shutdown(self) -> Result<(), WireError>

Gracefully shut down the client.
Source§

fn prompt( &mut self, user_input: impl Into<UserInput> + Send, ) -> impl Future<Output = Result<PromptResult, WireError>> + Send

Send a prompt and wait for the result.
Source§

fn start_prompt( &mut self, user_input: impl Into<UserInput> + Send, ) -> impl Future<Output = Result<String, WireError>> + Send

Send a prompt without waiting for the result.
Source§

fn replay( &mut self, ) -> impl Future<Output = Result<ReplayResult, WireError>> + Send

Replay events and requests from the current session.
Source§

fn steer( &mut self, user_input: impl Into<UserInput> + Send, ) -> impl Future<Output = Result<SteerResult, WireError>> + Send

Steer the current turn with additional user input.
Source§

fn set_plan_mode( &mut self, enabled: bool, ) -> impl Future<Output = Result<SetPlanModeResult, WireError>> + Send

Enable or disable plan mode.
Source§

fn cancel(&mut self) -> impl Future<Output = Result<(), WireError>> + Send

Cancel the current turn.

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, 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