Skip to main content

CommandDispatcher

Trait CommandDispatcher 

Source
pub trait CommandDispatcher: Send + Sync {
    // Required methods
    fn dispatch<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        cmd: &'life1 Command,
        ctx: &'life2 mut ExecContext,
    ) -> Pin<Box<dyn Future<Output = Result<ExecResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn eval_expr<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        expr: &'life1 Expr,
        ctx: &'life2 ExecContext,
    ) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn fork<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Arc<dyn CommandDispatcher>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn dispatch_stmt<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _stmt: &'life1 Stmt,
        _ctx: &'life2 mut ExecContext,
    ) -> Pin<Box<dyn Future<Output = Result<ExecResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn fork_attached<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Arc<dyn CommandDispatcher>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Trait for dispatching a single command through the full resolution chain.

Implementations handle argument parsing, tool lookup, and execution. The pipeline runner handles I/O routing (stdin, redirects, piping).

Required Methods§

Source

fn dispatch<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, cmd: &'life1 Command, ctx: &'life2 mut ExecContext, ) -> Pin<Box<dyn Future<Output = Result<ExecResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Dispatch a single command for execution.

The ctx provides stdin (from pipe or redirect), scope, and backend. Implementations should handle schema-aware argument parsing and output format extraction internally.

Source

fn eval_expr<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, expr: &'life1 Expr, ctx: &'life2 ExecContext, ) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Evaluate an expression through the full async chain.

Unlike the runner’s sync eval_simple_expr, this can run command substitution ($(...)) because it has access to pipeline execution. Used for redirect targets and heredoc bodies so cat < $(cmd), echo x > $(cmd), and $(...) inside heredoc bodies work. The ctx carries scope/cwd/backend for dispatchers that evaluate against it; stateful dispatchers (Kernel) snapshot their own session state and only let command output escape (side effects like cd do not).

Source

fn fork<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Arc<dyn CommandDispatcher>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Fork the dispatcher for concurrent execution (detached).

Returns a subsidiary dispatcher with independent mutable state, safe to run concurrently with the parent and other forks without data races on shared scope/cwd/aliases. Used by background & jobs, where the fork must survive parent cancellation.

For stateful dispatchers (e.g. Kernel) this snapshots per-session state into a fresh instance. Stateless dispatchers may clone.

Provided Methods§

Source

fn dispatch_stmt<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _stmt: &'life1 Stmt, _ctx: &'life2 mut ExecContext, ) -> Pin<Box<dyn Future<Output = Result<ExecResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Dispatch a compound statement (if, for, while, case) that sits in a pipeline stage.

The statement runs to completion and its whole output comes back in the ExecResult; PipelineRunner then writes those bytes to the pipe. So ctx.pipe_stdout must stay with the runner — hand it to the statement and the first nested command inside it would take the writer and the rest of the loop would write nowhere.

The default rejects the form. Only a dispatcher that can execute a whole statement (the Kernel) overrides it; a dispatcher that resolves one command at a time has nothing to run a loop body with, and saying so beats returning empty output at exit 0.

Source

fn fork_attached<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Arc<dyn CommandDispatcher>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Fork the dispatcher for concurrent execution (attached to parent cancel).

Like Self::fork but the fork’s cancellation token is a child of the parent’s. Cancelling the parent (timeout, Ctrl-C, embedder Kernel::cancel) cascades into the fork, which then kills its own external children via the usual SIGTERM/SIGKILL discipline.

Used for foreground concurrency: scatter workers, concurrent pipeline stages, command substitution. Default implementation delegates to Self::fork for stateless dispatchers that don’t track cancellation.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§