Skip to main content

ProcessContext

Trait ProcessContext 

Source
pub trait ProcessContext: Send + Sync {
    // Required methods
    fn run_command(
        &self,
        cmd: &str,
        args: &[&str],
    ) -> Result<Vec<u8>, BntoError>;
    fn temp_file(&self, suffix: &str) -> Result<PathBuf, BntoError>;
    fn env_var(&self, key: &str) -> Option<String>;
    fn work_dir(&self) -> Result<&Path, BntoError>;

    // Provided methods
    fn run_command_streaming(
        &self,
        cmd: &str,
        args: &[&str],
        on_output: &dyn Fn(&str),
    ) -> Result<Vec<u8>, BntoError> { ... }
    fn find_binary(&self, name: &str) -> Option<PathBuf> { ... }
    fn home_dir(&self) -> Option<&Path> { ... }
    fn output_dir(&self) -> Option<PathBuf> { ... }
    fn dry_run(&self) -> bool { ... }
}
Expand description

System access boundary for processors that need external tools.

Required Methods§

Source

fn run_command(&self, cmd: &str, args: &[&str]) -> Result<Vec<u8>, BntoError>

Run an external command, capturing stdout.

Source

fn temp_file(&self, suffix: &str) -> Result<PathBuf, BntoError>

Return a unique temporary file path with atomic creation (mkstemp). The file IS pre-created on disk to prevent TOCTOU races.

Source

fn env_var(&self, key: &str) -> Option<String>

Read an environment variable.

Source

fn work_dir(&self) -> Result<&Path, BntoError>

Get the working directory for this execution.

Provided Methods§

Source

fn run_command_streaming( &self, cmd: &str, args: &[&str], on_output: &dyn Fn(&str), ) -> Result<Vec<u8>, BntoError>

Run an external command, streaming output lines via a callback.

Calls on_output for each line of stdout and stderr as it arrives, enabling live progress feedback from tools like yt-dlp. Returns stdout bytes on success. Default falls back to run_command().

Source

fn find_binary(&self, name: &str) -> Option<PathBuf>

Locate the executable run_command(name, ..) would spawn, without spawning anything. Returns None when it can’t be found — always in the browser (WASM), which has no processes.

Source

fn home_dir(&self) -> Option<&Path>

Get the bnto home directory (~/.bnto/ by default). Returns None in browser (WASM) — filesystem paths don’t apply.

Source

fn output_dir(&self) -> Option<PathBuf>

Get the default output directory for recipe results (~/.bnto/output/). Returns None in browser (WASM) — filesystem paths don’t apply.

Source

fn dry_run(&self) -> bool

True on a dry run: a node that writes decides what it would do and writes nothing. Defaults to false.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§