Struct Engine

Source
pub struct Engine<Output> { /* private fields */ }
Expand description

Engine is the main part that can be implemented in any way.

This is a default Engine which acts as a container for the Commands which it can also execute based on the raw input.

You can disable default features to ignore this default Engine implementation and create your own.

To use the async version enable async feature.

Example:

let mut engine = Engine::new();
engine.add(/* your command here */);

let x = engine.execute(/* your input here */);

Implementations§

Source§

impl<Output: 'static> Engine<Output>

Source

pub fn new() -> Self

Creates a new empty Engine.

Source

pub fn insert<T: Command<Output = Output>>(&mut self, command: T)

Adds a new Command.

Each structure added need to implement Command trait and will be transformed into a trait object.

If Command with the same caller already exists in the Engine it will be overwritten.

Source

pub fn remove( &mut self, caller: impl AsRef<str>, ) -> Option<Box<dyn Command<Output = Output>>>

Removes Command based on its caller.

If the Command was present in the Engine it will be returned.

Source

pub fn is_empty(&self) -> bool

Checks if there are any Commands in the Engine.

Source

pub fn execute(&self, input: impl AsRef<str>) -> Result<Output, Error>

Based on the given input the Engine will choose related Command and trigger its on_execute method with the Instruction created from the input.

This function can fail if the input is not in a valid Instruction format, or if Engine failed to find any related Command.

Trait Implementations§

Source§

impl<T> Debug for Engine<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Default for Engine<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Output> Freeze for Engine<Output>

§

impl<Output> !RefUnwindSafe for Engine<Output>

§

impl<Output> !Send for Engine<Output>

§

impl<Output> !Sync for Engine<Output>

§

impl<Output> Unpin for Engine<Output>

§

impl<Output> !UnwindSafe for Engine<Output>

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.