pub struct CommandDispatcher<S>{
pub root: Arc<RwLock<CommandNode<S>>>,
}
Expand description
The root of the command tree. You need to make this to register commands.
let mut subject = CommandDispatcher::<CommandSource>::new();
Fields§
§root: Arc<RwLock<CommandNode<S>>>
Implementations§
Source§impl<S> CommandDispatcher<S>
impl<S> CommandDispatcher<S>
pub fn new() -> Self
Sourcepub fn register(
&mut self,
node: ArgumentBuilder<S>,
) -> Arc<RwLock<CommandNode<S>>>
pub fn register( &mut self, node: ArgumentBuilder<S>, ) -> Arc<RwLock<CommandNode<S>>>
Add a new node to the root.
subject.register(literal("foo").executes(|_| 42));
pub fn parse(&self, command: StringReader, source: S) -> ParseResults<'_, S>
Sourcepub fn execute(
&self,
input: impl Into<StringReader>,
source: S,
) -> Result<i32, CommandSyntaxException>
pub fn execute( &self, input: impl Into<StringReader>, source: S, ) -> Result<i32, CommandSyntaxException>
Parse and execute the command using the given input and context. The number returned depends on the command, and may not be of significance.
This is a shortcut for Self::parse
and Self::execute_parsed
.
pub fn add_paths( node: Arc<RwLock<CommandNode<S>>>, result: &mut Vec<Vec<Arc<RwLock<CommandNode<S>>>>>, parents: Vec<Arc<RwLock<CommandNode<S>>>>, )
pub fn get_path(&self, target: CommandNode<S>) -> Vec<String>
pub fn find_node(&self, path: &[&str]) -> Option<Arc<RwLock<CommandNode<S>>>>
Sourcepub fn execute_parsed(
parse: ParseResults<'_, S>,
) -> Result<i32, CommandSyntaxException>
pub fn execute_parsed( parse: ParseResults<'_, S>, ) -> Result<i32, CommandSyntaxException>
Executes a given pre-parsed command.
pub fn get_all_usage( &self, node: &CommandNode<S>, source: &S, restricted: bool, ) -> Vec<String>
Sourcepub fn get_smart_usage(
&self,
node: &CommandNode<S>,
source: &S,
) -> Vec<(Arc<RwLock<CommandNode<S>>>, String)>
pub fn get_smart_usage( &self, node: &CommandNode<S>, source: &S, ) -> Vec<(Arc<RwLock<CommandNode<S>>>, String)>
Gets the possible executable commands from a specified node.
You may use Self::root
as a target to get usage data for the entire
command tree.
pub fn get_completion_suggestions(parse: ParseResults<'_, S>) -> Suggestions
pub fn get_completion_suggestions_with_cursor( parse: ParseResults<'_, S>, cursor: usize, ) -> Suggestions
Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for CommandDispatcher<S>
impl<S> !RefUnwindSafe for CommandDispatcher<S>
impl<S> Send for CommandDispatcher<S>
impl<S> Sync for CommandDispatcher<S>
impl<S> Unpin for CommandDispatcher<S>
impl<S> !UnwindSafe for CommandDispatcher<S>
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