Struct shellfish::shell::Shell

source ·
pub struct Shell<'a, T, M: Display, H, I: InputHandler> {
    pub prompt: M,
    pub commands: HashMap<&'a str, Command<T>>,
    pub state: T,
    pub handler: H,
    pub description: String,
    pub input_handler: I,
}
Expand description

A shell represents a shell for editing commands in.

Here are the generics:

  • T: The state.
  • M: The prompt. Can be anything that can be printed.
  • H: The handler. Should implement either Handler or AsyncHandler, or no functionality is present.
  • I: The input handler. Must implement InputHandler

Fields§

§prompt: M

The shell prompt.

It can be anything which implements Display and can therefore be printed (This allows for prompts that change with the state.)

§commands: HashMap<&'a str, Command<T>>

This is a list of commands for the shell. The hashmap key is the name of the command (ie "greet") and the value is a wrapper to the function it corresponds to (as well as help information.)

§state: T

This is the state of the shell. This stores any values that you need to be persisted over multiple shell commands. For example it may be a simple counter or maybe a session ID.

§handler: H

This is the handler for commands. See the Handler documentation for more.

§description: String

This is the description of the shell as a whole. This is displayed when requesting help information.

§input_handler: I

The input method

Implementations§

source§

impl<'a, T, M: Display> Shell<'a, T, M, DefaultHandler, IO>

source

pub fn new(state: T, prompt: M) -> Self

Creates a new shell

If you have the rustyline feature enabled use [new_with_handler] to use the rustyline editor.

source§

impl<'a, T, M: Display> Shell<'a, T, M, DefaultAsyncHandler, IO>

source

pub fn new_async(state: T, prompt: M) -> Self

Available on crate feature async only.

Creates a new shell

If you have the rustyline feature enabled use [new_with_async_handler] to use the rustyline editor.

source§

impl<'a, T, M: Display, H: Handler<T>, I: InputHandler> Shell<'a, T, M, H, I>

source

pub fn new_with_handler( state: T, prompt: M, handler: H, input_handler: I ) -> Self

Creates a new shell with the given handler.

source

pub fn run(&mut self) -> Result<()>

Starts running the shell

source§

impl<'a, T: Send, M: Display, H: AsyncHandler<T>, I: InputHandler> Shell<'a, T, M, H, I>

source

pub fn new_with_async_handler( state: T, prompt: M, handler: H, input_handler: I ) -> Self

Available on crate feature async only.

Creates a new shell with the given handler.

source

pub async fn run_async(&mut self) -> Result<()>

Available on crate feature async only.

Starts running the shell

Trait Implementations§

source§

impl<'a, T: Clone, M: Clone + Display, H: Clone, I: Clone + InputHandler> Clone for Shell<'a, T, M, H, I>

source§

fn clone(&self) -> Shell<'a, T, M, H, I>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'f: 't, 't, T: Serialize + for<'a> Deserialize<'a>, M: Display, H: Handler<T>, I: InputHandler> TryFrom<Shell<'f, T, M, H, I>> for App<'t, T, DefaultCommandLineHandler>

Available on crate feature app only.
§

type Error = Box<dyn Error>

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

fn try_from(shell: Shell<'f, T, M, H, I>) -> Result<Self, Box<dyn Error>>

Performs the conversion.

Auto Trait Implementations§

§

impl<'a, T, M, H, I> RefUnwindSafe for Shell<'a, T, M, H, I>

§

impl<'a, T, M, H, I> Send for Shell<'a, T, M, H, I>
where H: Send, I: Send, M: Send, T: Send,

§

impl<'a, T, M, H, I> Sync for Shell<'a, T, M, H, I>
where H: Sync, I: Sync, M: Sync, T: Sync,

§

impl<'a, T, M, H, I> Unpin for Shell<'a, T, M, H, I>
where H: Unpin, I: Unpin, M: Unpin, T: Unpin,

§

impl<'a, T, M, H, I> UnwindSafe for Shell<'a, T, M, H, I>

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.