Skip to main content

Bash

Struct Bash 

Source
pub struct Bash { /* private fields */ }
Expand description

Main entry point for Bashkit.

Provides a sandboxed bash interpreter with an in-memory virtual filesystem.

Implementations§

Source§

impl Bash

Source

pub fn new() -> Self

Create a new Bash instance with default settings.

Source

pub fn builder() -> BashBuilder

Create a new BashBuilder for customized configuration.

Source

pub async fn exec(&mut self, script: &str) -> Result<ExecResult>

Execute a bash script and return the result.

This method first validates that the script does not exceed the maximum input size, then parses the script with a timeout, AST depth limit, and fuel limit, then executes the resulting AST.

Source

pub fn fs(&self) -> Arc<dyn FileSystem>

Get a clone of the underlying filesystem.

Provides direct access to the virtual filesystem for:

  • Pre-populating files before script execution
  • Reading binary file outputs after execution
  • Injecting test data or configuration
§Example
use bashkit::Bash;
use std::path::Path;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut bash = Bash::new();
    let fs = bash.fs();

    // Pre-populate config file
    fs.mkdir(Path::new("/config"), false).await?;
    fs.write_file(Path::new("/config/app.txt"), b"debug=true\n").await?;

    // Bash script can read pre-populated files
    let result = bash.exec("cat /config/app.txt").await?;
    assert_eq!(result.stdout, "debug=true\n");

    // Bash creates output, read it directly
    bash.exec("echo 'done' > /output.txt").await?;
    let output = fs.read_file(Path::new("/output.txt")).await?;
    assert_eq!(output, b"done\n");
    Ok(())
}

Trait Implementations§

Source§

impl Default for Bash

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Bash

§

impl !RefUnwindSafe for Bash

§

impl Send for Bash

§

impl Sync for Bash

§

impl Unpin for Bash

§

impl !UnwindSafe for Bash

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.