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>
impl<Output: 'static> Engine<Output>
Sourcepub fn insert<T: Command<Output = Output>>(&mut self, command: T)
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.
Sourcepub fn remove(
&mut self,
caller: impl AsRef<str>,
) -> Option<Box<dyn Command<Output = Output>>>
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.
Sourcepub fn execute(&self, input: impl AsRef<str>) -> Result<Output, Error>
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.