Skip to main content

Shell

Struct Shell 

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

Struct representing the state of the shell, it should be created using Shell::setup() which will handle all necessary initialization such as setting up the REPL editor and loading history from file, and should be used to run the main REPL loop with Shell::run() finally, Shell::exit() should be called before exiting the program to handle any necessary cleanup such as writing history back to file

§Example:


fn main() -> clawsh::Result<()> {
    let mut shell = Shell::setup()?;
    shell.run();
    shell.exit()?;
    Ok(())
}

Implementations§

Source§

impl Shell

Source

pub fn run(&mut self)

Main REPL loop for the shell, continuously reading user input, parsing it, and executing commands until an exit condition is met (e.g. exit command, EOF, or interrupt) internal errors during command handling are printed to stderr but do not exit the shell

Source§

impl Shell

Source

pub fn setup() -> Result<Self, ClawshSetupError>

Setup a new Shell instance

§Errors
  • ClawshSetupError::CreateHistFile if the history file specified by HISTFILE environment variable does not exist and cannot be created
  • ClawshSetupError::ReadHistFile if the history file specified by HISTFILE environment variable cannot be read
  • ClawshSetupError::CreateEditor if the rustyline::Editor cannot be created for the REPL
Source

pub fn exit(self) -> Result<(), ClawshExitError>

Exit the shell writing history back to file specified by HISTFILE environment variable if it is set if HISTFILE is not set, no history will be written and the function will return Ok(())

§Errors
  • ClawshExitError::CouldNotOpenHistFile if the history file specified by HISTFILE environment variable cannot be opened for writing during shell exit

Auto Trait Implementations§

§

impl Freeze for Shell

§

impl !RefUnwindSafe for Shell

§

impl Send for Shell

§

impl Sync for Shell

§

impl Unpin for Shell

§

impl UnsafeUnpin for Shell

§

impl !UnwindSafe for Shell

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.