DialogExecutor

Struct DialogExecutor 

Source
pub struct DialogExecutor {
    pub max_steps: usize,
    pub default_timeout: Duration,
}
Expand description

Dialog execution state.

Fields§

§max_steps: usize

Maximum number of steps to execute.

§default_timeout: Duration

Default timeout for steps without explicit timeout.

Implementations§

Source§

impl DialogExecutor

Source

pub fn new() -> Self

Create a new executor.

Source

pub const fn max_steps(self, max: usize) -> Self

Set the maximum number of steps.

Source

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

Set the default timeout.

Source

pub fn execute_step_sync( &self, step: &DialogStep, dialog: &Dialog, _buffer: &str, ) -> StepResult

Execute a single step (synchronously - for testing).

This method prepares a step for execution by:

  • Substituting variables in the send text
  • Determining the next step to execute

Note: This is a synchronous helper primarily for testing. For actual dialog execution, use the async session-based execution methods.

Source

pub fn step_pattern( &self, step: &DialogStep, dialog: &Dialog, ) -> Option<Pattern>

Get the pattern for a step.

Source

pub async fn execute<T>( &self, session: &mut Session<T>, dialog: &Dialog, ) -> Result<DialogResult>

Execute a dialog on a session.

This runs through the dialog steps, expecting patterns and sending responses.

§Example
use rust_expect::{Session, Dialog, DialogStep, DialogExecutor};

#[tokio::main]
async fn main() -> Result<(), rust_expect::ExpectError> {
    let mut session = Session::spawn("/bin/bash", &[]).await?;

    let dialog = Dialog::named("login")
        .step(DialogStep::new("prompt")
            .with_expect("$")
            .with_send("echo hello\n"));

    let executor = DialogExecutor::new();
    let result = executor.execute(&mut session, &dialog).await?;
    assert!(result.success);
    Ok(())
}
§Errors

Returns an error if:

  • A step times out without continue_on_timeout set
  • The session closes unexpectedly
  • An I/O error occurs
Source

pub async fn execute_step<T>( &self, session: &mut Session<T>, step: &DialogStep, dialog: &Dialog, ) -> Result<StepResult>

Execute a single dialog step on a session.

§Errors

Returns an error if an I/O error occurs (timeouts are handled per-step).

Trait Implementations§

Source§

impl Debug for DialogExecutor

Source§

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

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

impl Default for DialogExecutor

Source§

fn default() -> Self

Returns the “default value” for a 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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V