Skip to main content

RustBash

Struct RustBash 

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

A sandboxed bash shell interpreter.

Implementations§

Source§

impl RustBash

Source

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

Execute a shell command string and return the result.

Source

pub fn cwd(&self) -> &str

Returns the current working directory.

Source

pub fn last_exit_code(&self) -> i32

Returns the exit code of the last executed command.

Source

pub fn should_exit(&self) -> bool

Returns true if the shell received an exit command.

Source

pub fn command_names(&self) -> Vec<&str>

Returns the names of all registered commands (builtins + custom).

Source

pub fn command_meta(&self, name: &str) -> Option<&'static CommandMeta>

Returns the CommandMeta for a registered command, if it provides one.

Source

pub fn set_shell_name(&mut self, name: String)

Sets the shell name ($0).

Source

pub fn set_positional_params(&mut self, params: Vec<String>)

Sets the positional parameters ($1, $2, …).

Source

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

Returns a reference to the virtual filesystem.

Source

pub fn write_file(&self, path: &str, content: &[u8]) -> Result<(), VfsError>

Write a file to the virtual filesystem, creating parent directories.

Source

pub fn read_file(&self, path: &str) -> Result<Vec<u8>, VfsError>

Read a file from the virtual filesystem.

Source

pub fn mkdir(&self, path: &str, recursive: bool) -> Result<(), VfsError>

Create a directory in the virtual filesystem.

Source

pub fn exists(&self, path: &str) -> bool

Check if a path exists in the virtual filesystem.

Source

pub fn readdir(&self, path: &str) -> Result<Vec<DirEntry>, VfsError>

List entries in a directory.

Source

pub fn stat(&self, path: &str) -> Result<Metadata, VfsError>

Get metadata for a path.

Source

pub fn remove_file(&self, path: &str) -> Result<(), VfsError>

Remove a file from the virtual filesystem.

Source

pub fn remove_dir_all(&self, path: &str) -> Result<(), VfsError>

Remove a directory (and contents if recursive) from the virtual filesystem.

Source

pub fn register_command(&mut self, cmd: Arc<dyn VirtualCommand>)

Register a custom command.

Source

pub fn exec_with_overrides( &mut self, input: &str, env: Option<&HashMap<String, String>>, cwd: Option<&str>, stdin: Option<&str>, ) -> Result<ExecResult, RustBashError>

Execute a command with per-exec environment and cwd overrides.

Overrides are applied before execution and restored afterward.

Source

pub fn is_input_complete(input: &str) -> bool

Check whether input looks like a complete shell statement.

Returns true when the input can be tokenized and parsed without hitting an “unexpected end-of-input” / unterminated-quote error. Useful for implementing multi-line REPL input.

Note: mirrors the tokenize → parse flow from interpreter::parse().

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more