pub trait ShellHost: Send {
Show 26 methods
// Provided methods
fn glob(&mut self, pattern: &str, recursive: bool) -> Vec<String> { ... }
fn tilde_expand(&mut self, s: &str) -> String { ... }
fn brace_expand(&mut self, s: &str) -> Vec<String> { ... }
fn word_split(&mut self, s: &str) -> Vec<String> { ... }
fn expand_param(
&mut self,
name: &str,
modifier: u8,
args: &[Value],
) -> Value { ... }
fn array_index(&mut self, name: &str, index: &Value) -> Value { ... }
fn cmd_subst(&mut self, sub: &Chunk) -> String { ... }
fn process_sub_in(&mut self, sub: &Chunk) -> String { ... }
fn process_sub_out(&mut self, sub: &Chunk) -> String { ... }
fn redirect(&mut self, fd: u8, op: u8, target: &str) { ... }
fn heredoc(&mut self, content: &str) { ... }
fn herestring(&mut self, content: &str) { ... }
fn pipeline_begin(&mut self, n: u8) { ... }
fn pipeline_stage(&mut self) { ... }
fn pipeline_end(&mut self) -> i32 { ... }
fn subshell_begin(&mut self) { ... }
fn subshell_end(&mut self) -> Option<i32> { ... }
fn trap_set(&mut self, sig: &str, handler: &Chunk) { ... }
fn trap_check(&mut self) { ... }
fn with_redirects_begin(&mut self, count: u8) { ... }
fn with_redirects_end(&mut self) { ... }
fn call_function(&mut self, name: &str, args: Vec<String>) -> Option<i32> { ... }
fn exec(&mut self, args: Vec<String>) -> i32 { ... }
fn exec_bg(&mut self, args: Vec<String>) -> i32 { ... }
fn str_match(&mut self, s: &str, pat: &str) -> bool { ... }
fn regex_match(&mut self, s: &str, regex: &str) -> bool { ... }
}Expand description
Frontend-supplied implementation of shell-specific runtime behavior.
All methods have default no-op or identity implementations so frontends only override what they need.
Provided Methods§
Sourcefn glob(&mut self, pattern: &str, recursive: bool) -> Vec<String>
fn glob(&mut self, pattern: &str, recursive: bool) -> Vec<String>
Glob expand pattern. If recursive, treat ** as a recursive marker.
Returns the matched paths (empty when no match — caller decides how to
handle nullglob/nomatch options).
Sourcefn tilde_expand(&mut self, s: &str) -> String
fn tilde_expand(&mut self, s: &str) -> String
Tilde expansion: ~ → $HOME, ~user → user’s home, ~+/~- → dir stack.
Returns input unchanged if no expansion applies.
Sourcefn brace_expand(&mut self, s: &str) -> Vec<String>
fn brace_expand(&mut self, s: &str) -> Vec<String>
Brace expansion: {a,b} → [“a”,“b”], {1..10} → 10 strings.
Returns a single-element vec containing the input when no braces present.
Sourcefn word_split(&mut self, s: &str) -> Vec<String>
fn word_split(&mut self, s: &str) -> Vec<String>
Word splitting using current IFS rules.
Sourcefn expand_param(&mut self, name: &str, modifier: u8, args: &[Value]) -> Value
fn expand_param(&mut self, name: &str, modifier: u8, args: &[Value]) -> Value
Parameter expansion: ${var:-default}, ${#var}, ${var/pat/rep}, etc.
modifier is one of crate::op::param_mod::*.
args are the modifier operands (already evaluated to Values) — for
${var:-x} it’s [x], for ${var/p/r} it’s [p, r], for ${var:o:l}
it’s [o, l]. LENGTH/UPPER/LOWER/KEYS/INDIRECT take no args.
Sourcefn array_index(&mut self, name: &str, index: &Value) -> Value
fn array_index(&mut self, name: &str, index: &Value) -> Value
Index into an array variable: ${arr[idx]}. index is the evaluated
subscript (Int for indexed arrays, Str for associative).
Sourcefn cmd_subst(&mut self, sub: &Chunk) -> String
fn cmd_subst(&mut self, sub: &Chunk) -> String
Run a sub-chunk and capture its stdout as a string. ($(cmd),`cmd`)
Sourcefn process_sub_in(&mut self, sub: &Chunk) -> String
fn process_sub_in(&mut self, sub: &Chunk) -> String
Process substitution input: spawn sub, return path to a fd/FIFO that
reads its stdout. (<(cmd))
Sourcefn process_sub_out(&mut self, sub: &Chunk) -> String
fn process_sub_out(&mut self, sub: &Chunk) -> String
Process substitution output: spawn sub, return path to a fd/FIFO that
writes to its stdin. (>(cmd))
Sourcefn redirect(&mut self, fd: u8, op: u8, target: &str)
fn redirect(&mut self, fd: u8, op: u8, target: &str)
Apply a redirection at the next exec/builtin call.
fd is the source fd, op from crate::op::redirect_op::*, target
is the (already-expanded) filename or fd reference.
Sourcefn herestring(&mut self, content: &str)
fn herestring(&mut self, content: &str)
Herestring body for the next command’s stdin.
Sourcefn pipeline_begin(&mut self, n: u8)
fn pipeline_begin(&mut self, n: u8)
Begin an N-stage pipeline. Subsequent pipeline_stage calls separate
stages; pipeline_end waits for completion and returns final status.
Sourcefn pipeline_stage(&mut self)
fn pipeline_stage(&mut self)
Wire next pipeline stage (set up pipe between previous and next).
Sourcefn pipeline_end(&mut self) -> i32
fn pipeline_end(&mut self) -> i32
Wait for the pipeline to complete; return last command’s exit status.
Sourcefn subshell_begin(&mut self)
fn subshell_begin(&mut self)
Begin subshell scope (snapshot/save state).
Sourcefn subshell_end(&mut self) -> Option<i32>
fn subshell_end(&mut self) -> Option<i32>
End subshell scope (restore state). Returns Some(status) when
the subshell terminated with a deferred exit (the host wants the
VM’s last_status updated so the parent’s $? sees the exit
value); returns None to leave last_status untouched.
Sourcefn trap_set(&mut self, sig: &str, handler: &Chunk)
fn trap_set(&mut self, sig: &str, handler: &Chunk)
Install a trap handler for signal sig. The handler is a sub-chunk
that the host runs when the signal fires.
Sourcefn trap_check(&mut self)
fn trap_check(&mut self)
Process pending traps (called periodically by the VM dispatch loop).
Sourcefn with_redirects_begin(&mut self, count: u8)
fn with_redirects_begin(&mut self, count: u8)
Begin scoped redirect block — cmd > out.txt style applied to a
compound command. The host saves current fd state.
Sourcefn with_redirects_end(&mut self)
fn with_redirects_end(&mut self)
End scoped redirect block — restore fd state.
Sourcefn call_function(&mut self, name: &str, args: Vec<String>) -> Option<i32>
fn call_function(&mut self, name: &str, args: Vec<String>) -> Option<i32>
Call a user-defined shell function. Returns Some(status) when the
function exists, None to fall through to external exec.
Sourcefn exec(&mut self, args: Vec<String>) -> i32
fn exec(&mut self, args: Vec<String>) -> i32
Spawn an external command and wait. Default uses std::process::Command.
On wasm32 (a browser web worker) there is no process model, so the
default returns 127 (command-not-found) rather than attempting a spawn
— a worker frontend overrides this to bridge to the host environment.
Sourcefn exec_bg(&mut self, args: Vec<String>) -> i32
fn exec_bg(&mut self, args: Vec<String>) -> i32
Spawn an external command in the background and detach. Returns the
child pid (or 0 on failure / when the host doesn’t track pids). Default
uses std::process::Command::spawn(). Frontends override to register
the pid in their job table so jobs, fg, wait, disown see it.
On wasm32 there is no process model; returns 0 (no pid tracked)
unless a worker frontend overrides it.
Sourcefn str_match(&mut self, s: &str, pat: &str) -> bool
fn str_match(&mut self, s: &str, pat: &str) -> bool
Glob match: does s match the shell glob pattern pat?
Used by [[ x = pat ]] and case. Default is exact equality.
Sourcefn regex_match(&mut self, s: &str, regex: &str) -> bool
fn regex_match(&mut self, s: &str, regex: &str) -> bool
Regex match: s =~ regex (extended POSIX or PCRE per host).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".