Struct hecs::CommandBuffer

source ·
pub struct CommandBuffer { /* private fields */ }
Expand description

Records operations for future application to a World

Useful when operations cannot be applied directly due to ordering concerns or borrow checking.

let mut world = World::new();
let entity = world.reserve_entity();
let mut cmd = CommandBuffer::new();
cmd.insert(entity, (true, 42));
cmd.run_on(&mut world); // cmd can now be reused
assert_eq!(*world.get::<&i32>(entity).unwrap(), 42);

Implementations§

Create an empty command buffer

Add components from bundle to entity, if it exists

Pairs well with World::reserve_entity to spawn entities with a known handle.

When inserting a single component, see insert_one for convenience.

Add component to entity, if the entity exists

See insert.

Remove components from entity if they exist

When removing a single component, see remove_one for convenience.

Remove a component from entity if it exists

See remove.

Despawn entity from World

Spawn a new entity with components

If the Entity is needed immediately, consider combining World::reserve_entity with insert instead.

Run recorded commands on world, clearing the command buffer

Drop all recorded commands

Trait Implementations§

Create an empty buffer

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.