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§

source§

impl CommandBuffer

source

pub fn new() -> CommandBuffer

Create an empty command buffer

source

pub fn insert(&mut self, entity: Entity, components: impl DynamicBundle)

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.

source

pub fn insert_one(&mut self, entity: Entity, component: impl Component)

Add component to entity, if the entity exists

See insert.

source

pub fn remove<T>(&mut self, ent: Entity)where T: Bundle + 'static,

Remove components from entity if they exist

When removing a single component, see remove_one for convenience.

source

pub fn remove_one<T>(&mut self, ent: Entity)where T: Component,

Remove a component from entity if it exists

See remove.

source

pub fn despawn(&mut self, entity: Entity)

Despawn entity from World

source

pub fn spawn(&mut self, components: impl DynamicBundle)

Spawn a new entity with components

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

source

pub fn run_on(&mut self, world: &mut World)

Run recorded commands on world, clearing the command buffer

source

pub fn clear(&mut self)

Drop all recorded commands

Trait Implementations§

source§

impl Default for CommandBuffer

source§

fn default() -> CommandBuffer

Create an empty buffer

source§

impl Drop for CommandBuffer

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Send for CommandBuffer

source§

impl Sync for CommandBuffer

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> Any for Twhere T: Any,

source§

impl<T> Component for Twhere T: Send + Sync + 'static,

§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,