pub struct DialogExecutor {
pub max_steps: usize,
pub default_timeout: Duration,
}Expand description
Dialog execution state.
Fields§
§max_steps: usizeMaximum number of steps to execute.
default_timeout: DurationDefault timeout for steps without explicit timeout.
Implementations§
Source§impl DialogExecutor
impl DialogExecutor
Sourcepub const fn default_timeout(self, timeout: Duration) -> Self
pub const fn default_timeout(self, timeout: Duration) -> Self
Set the default timeout.
Sourcepub fn execute_step_sync(
&self,
step: &DialogStep,
dialog: &Dialog,
_buffer: &str,
) -> StepResult
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.
Sourcepub fn step_pattern(
&self,
step: &DialogStep,
dialog: &Dialog,
) -> Option<Pattern>
pub fn step_pattern( &self, step: &DialogStep, dialog: &Dialog, ) -> Option<Pattern>
Get the pattern for a step.
Sourcepub async fn execute<T>(
&self,
session: &mut Session<T>,
dialog: &Dialog,
) -> Result<DialogResult>
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_timeoutset - The session closes unexpectedly
- An I/O error occurs
Sourcepub async fn execute_step<T>(
&self,
session: &mut Session<T>,
step: &DialogStep,
dialog: &Dialog,
) -> Result<StepResult>
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
impl Debug for DialogExecutor
Auto Trait Implementations§
impl Freeze for DialogExecutor
impl RefUnwindSafe for DialogExecutor
impl Send for DialogExecutor
impl Sync for DialogExecutor
impl Unpin for DialogExecutor
impl UnwindSafe for DialogExecutor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more