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 home_dir(&self) -> Option<&Path> { ... }
    fn output_dir(&self) -> Option<PathBuf> { ... }
}
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 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.

Implementors§