pub struct CommandRegistry { /* private fields */ }Expand description
A simple in-game console command registry.
Commands are registered with a name, description, and a handler function
that accepts Vec<String> args and returns a String result (or an error
string).
Implementations§
Source§impl CommandRegistry
impl CommandRegistry
pub fn new() -> Self
Sourcepub fn register(
&mut self,
name: impl Into<String>,
description: impl Into<String>,
handler: Box<dyn Fn(Vec<String>) -> String + Send + Sync>,
)
pub fn register( &mut self, name: impl Into<String>, description: impl Into<String>, handler: Box<dyn Fn(Vec<String>) -> String + Send + Sync>, )
Register a command with a name, description, and handler.
Sourcepub fn add_alias(&mut self, name: &str, alias: impl Into<String>)
pub fn add_alias(&mut self, name: &str, alias: impl Into<String>)
Add an alias for an existing command.
Sourcepub fn unregister(&mut self, name: &str)
pub fn unregister(&mut self, name: &str)
Unregister a command by name.
Sourcepub fn execute(&self, input: &str) -> Result<String, String>
pub fn execute(&self, input: &str) -> Result<String, String>
Execute a raw input string. Parses the first token as the command name and the remainder as space-separated arguments.
Sourcepub fn completions(&self, prefix: &str) -> Vec<String>
pub fn completions(&self, prefix: &str) -> Vec<String>
Return all command names that start with prefix, sorted.
pub fn is_empty(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CommandRegistry
impl !RefUnwindSafe for CommandRegistry
impl Send for CommandRegistry
impl Sync for CommandRegistry
impl Unpin for CommandRegistry
impl UnsafeUnpin for CommandRegistry
impl !UnwindSafe for CommandRegistry
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.