pub fn add_command(
        &mut self,
        command: Command,
        func: impl FnMut(Context) -> Result<Response> + Send + Sync + 'static,
    ) -> &mut Self {
        // Combine the command name and aliases into a single array so we can map them later.
        let mut keys: Vec<String> = command
            .aliases
            .iter()
            .map(|s| s.to_lowercase())
            .collect::<_>();
        keys.push(command.name.to_lowercase());

        // Create the handle; we move the command and func at this point.
        self.commands.push(CommandHandle {
            inner: command,
            func: Box::new(func),
        });

        // Create a mapping from each key (name or alias) to the index that the command handle is
        // stored at. This lets us access commands later simply by indexing in. This is much easier
        // than maintaining a map with multiple handles (which would require cloning or a lot of
        // ref handling - which would make the World struct more verbose to invoke for users).
        let map_index = self.commands.len() - 1;
        for key in keys {
            self.command_map.insert(key, map_index);
        }

        self
    }
/// Adds a command to the world. Commands are invoked by peers when sending a message and run
/// once on the next frame.
Adds a command to the world. Commands are invoked by peers when sending a message and run
once on the next frame.
Adds a command to the world . Commands are invoked by peers when sending a message and run once on the next frame .
pub fn add_command(
        &mut self,
        command: Command,
        func: impl FnMut(Context) -> Result<Response> + Send + Sync + 'static,
    ) -> &mut Self {
        // Combine the command name and aliases into a single array so we can map them later.
        let mut keys: Vec<String> = command
            .aliases
            .iter()
            .map(|s| s.to_lowercase())
            .collect::<_>();
        keys.push(command.name.to_lowercase());
        // Create the handle; we move the command and func at this point.
        self.commands.push(CommandHandle {
            inner: command,
            func: Box::new(func),
        });
        // Create a mapping from each key (name or alias) to the index that the command handle is
        // stored at. This lets us access commands later simply by indexing in. This is much easier
        // than maintaining a map with multiple handles (which would require cloning or a lot of
        // ref handling - which would make the World struct more verbose to invoke for users).
        let map_index = self.commands.len() - 1;
        for key in keys {
            self.command_map.insert(key, map_index);
        }
        self
    }
pub fn add_command ( & mut self , command : Command , func : impl FnMut ( Context ) -> Result < Response > + Send + Sync + ' static , ) -> & mut Self { // Combine the command name and aliases into a single array so we can map them later. let mut keys : Vec < String > = command . aliases . iter ( ) . map ( | s | s . to_lowercase ( ) ) . collect :: < _ > ( ) ; keys . push ( command . name . to_lowercase ( ) ) ; // Create the handle; we move the command and func at this point. self . commands . push ( CommandHandle { inner : command , func : Box :: new ( func ) , } ) ; // Create a mapping from each key (name or alias) to the index that the command handle is // stored at. This lets us access commands later simply by indexing in. This is much easier // than maintaining a map with multiple handles (which would require cloning or a lot of // ref handling - which would make the World struct more verbose to invoke for users). let map_index = self . commands . len ( ) - 1 ; for key in keys { self . command_map . insert ( key , map_index ) ; } self }
Adds a command to the world.
Adds a command to the world .
&mut self
command
Command
func
impl FnMut(Context) -> Result<Response> + Send + Sync + 'static
&mut self
command
Command
func
impl FnMut(Context) -> Result<Response> + Send + Sync + 'static