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
impl Shell
Sourcepub fn setup() -> Result<Self, ClawshSetupError>
pub fn setup() -> Result<Self, ClawshSetupError>
Setup a new Shell instance
§Errors
ClawshSetupError::CreateHistFileif the history file specified byHISTFILEenvironment variable does not exist and cannot be createdClawshSetupError::ReadHistFileif the history file specified byHISTFILEenvironment variable cannot be readClawshSetupError::CreateEditorif therustyline::Editorcannot be created for the REPL
Sourcepub fn exit(self) -> Result<(), ClawshExitError>
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::CouldNotOpenHistFileif the history file specified byHISTFILEenvironment 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more