Skip to main content

IOBridge

Struct IOBridge 

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

IO Bridge - Pure bridge between View and Model layers.

Converts between IO types (IOInput/IOOutput) and internal events (Signal). This is a stateless transformation layer.

Note: IOBridge does not hold a Principal. The Principal is provided by the owning ClientRunner when converting input to Signals.

The parser can be injected for testing or customization.

Implementations§

Source§

impl IOBridge

Source

pub fn new(io_port: IOPort) -> Self

Creates a new IOBridge with default parser.

§Arguments
  • io_port - IO port for View communication
Source

pub fn with_parser(io_port: IOPort, parser: InputParser) -> Self

Creates a new IOBridge with a custom parser.

This allows injecting a custom parser for testing or customization.

Source

pub fn channel_id(&self) -> ChannelId

Returns the channel ID.

Source

pub fn command_to_signal( &self, cmd: &InputCommand, principal: &Principal, default_approval_id: Option<&str>, ) -> Option<Signal>

Converts an InputCommand to a Signal.

§Arguments
  • cmd - The parsed input command
  • principal - Principal to use for the signal
  • default_approval_id - Fallback approval ID if command has none
Source

pub fn parse_line_to_signal( &self, line: &str, principal: &Principal, default_approval_id: Option<&str>, ) -> Option<Signal>

Parses a line of input and converts to Signal.

§Arguments
  • line - Raw input line
  • principal - Principal to use for the signal
  • default_approval_id - Fallback approval ID for HIL responses
Source

pub fn drain_input_to_signals( &mut self, principal: &Principal, ) -> (Vec<Signal>, Vec<InputCommand>)

Drains all available input and converts to Signals.

Returns a vector of Signals ready to be dispatched to EventBus. Also returns any InputCommands that couldn’t be converted (e.g., Quit, Unknown) for the caller to handle.

Approval IDs are extracted from the input context provided by View layer.

§Arguments
  • principal - Principal to use for signals
Source

pub async fn recv_input( &mut self, principal: &Principal, ) -> Option<Result<Signal, InputCommand>>

Receives a single input and processes it.

Async version - waits for input.

Approval IDs are extracted from the input context provided by View layer.

§Arguments
  • principal - Principal to use for signals
§Returns
  • Some(Ok(signal)) - Input converted to signal
  • Some(Err(cmd)) - Input is a command that doesn’t map to signal
  • None - IO port closed
Source

pub async fn send_output( &self, output: IOOutput, ) -> Result<(), SendError<IOOutput>>

Sends an output to the View layer.

§Errors

Returns error if the output handle has been dropped.

Source

pub async fn show_processing( &self, component: &str, operation: &str, ) -> Result<(), SendError<IOOutput>>

Displays a processing notification.

Source

pub async fn show_approval_request( &self, request: &ApprovalRequest, ) -> Result<(), SendError<IOOutput>>

Displays an approval request.

Source

pub async fn show_approved( &self, approval_id: &str, ) -> Result<(), SendError<IOOutput>>

Displays approval confirmation.

Source

pub async fn show_rejected( &self, approval_id: &str, reason: Option<&str>, ) -> Result<(), SendError<IOOutput>>

Displays rejection confirmation.

Source

pub async fn info(&self, message: &str) -> Result<(), SendError<IOOutput>>

Displays an info message.

Source

pub async fn warn(&self, message: &str) -> Result<(), SendError<IOOutput>>

Displays a warning message.

Source

pub async fn error(&self, message: &str) -> Result<(), SendError<IOOutput>>

Displays an error message.

Source

pub async fn prompt(&self, message: &str) -> Result<(), SendError<IOOutput>>

Displays a prompt message.

Source

pub fn is_output_closed(&self) -> bool

Returns true if the output channel is closed.

Trait Implementations§

Source§

impl Debug for IOBridge

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