Trait Command

Source
pub trait Command: Send + 'static {
    // Required method
    fn command(&mut self, ecs: Ecs<'_>) -> DynResult<()>;

    // Provided method
    fn cancel(&mut self) { ... }
}
Expand description

Command to an ECS instance.

Command is one way to modify ECS instance directly such as adding or removing systems. In the command method, an ECS handle is given and you can make change to the ECS insance using the handle.

§Example

use my_ecs::prelude::*;

struct MyCommand;

impl Command for MyCommand {
    fn command(&mut self, mut ecs: Ecs) -> DynResult<()> {
        ecs.add_system(|| { /* ... */}).take()?;
        Ok(())
    }
}

Required Methods§

Source

fn command(&mut self, ecs: Ecs<'_>) -> DynResult<()>

A method accessing the whole ECS instance.

After calling this method, the command will be dropped.

Provided Methods§

Source

fn cancel(&mut self)

Cancellation method which is called when the command cannot be executed for some reason.

After calling this method, the command will be dropped.

Trait Implementations§

Source§

impl Debug for dyn Command

Source§

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

Formats the value using the given formatter. Read more

Implementations on Foreign Types§

Source§

impl Command for ()

Empty command.

This implementation allows clients make commands returning just (), called unit.

Source§

fn command(&mut self, _ecs: Ecs<'_>) -> DynResult<()>

Source§

impl<F> Command for Option<F>
where F: FnOnce(Ecs<'_>) -> DynResult<()> + Send + 'static,

Source§

fn command(&mut self, ecs: Ecs<'_>) -> DynResult<()>

Implementors§

Source§

impl Command for DynResult<()>

Empty command.

This implementation helps clients to use ‘?’ operator in their command functions.

Source§

impl<F> Command for DynResult<F>
where F: FnOnce(Ecs<'_>) -> DynResult<()> + Send + 'static,

Source§

impl<F> Command for F
where F: FnMut(Ecs<'_>) -> DynResult<()> + Send + 'static,