Struct rusty_cmd::cmd::Cmd

source ·
pub struct Cmd<R: BufRead, W: Write> { /* private fields */ }
Expand description

Command interpreter implemented as struct that contains boxed CommandHandlers in a hashmap with Strings as the keys

Implementations§

source§

impl<R: BufRead + 'static, W: Write + 'static> Cmd<R, W>

source

pub fn new(reader: R, writer: W) -> Cmd<R, W>
where W: Write, R: Read,

Create new Cmd instance

source

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

Start the command interpreter

Handlers with return code 0 will break the loop

source

pub fn add_cmd( &mut self, name: String, handler: Box<dyn CommandHandler<W>> ) -> Result<(), Error>

Insert new command into the Cmd handles HashMap

§Note: Will not overwrite existing handler names

Trait Implementations§

source§

impl<R: Debug + BufRead, W: Debug + Write> Debug for Cmd<R, W>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R, W> Freeze for Cmd<R, W>
where R: Freeze, W: Freeze,

§

impl<R, W> !RefUnwindSafe for Cmd<R, W>

§

impl<R, W> !Send for Cmd<R, W>

§

impl<R, W> !Sync for Cmd<R, W>

§

impl<R, W> Unpin for Cmd<R, W>
where R: Unpin, W: Unpin,

§

impl<R, W> !UnwindSafe for Cmd<R, W>

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

§

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.