pub struct Commands<'w> {
world: &'w World,
scope: Entity,
}Expand description
A queue of structural changes, all of them in one scope.
The queue lives in the world, so deferring a spawn from a callback to the driver needs no channel.
Fields§
§world: &'w World§scope: EntityImplementations§
Source§impl<'w> Commands<'w>
impl<'w> Commands<'w>
pub(crate) fn new(world: &'w World, scope: Entity) -> Self
Sourcepub fn spawn<B: Bundle + 'static>(&self, bundle: B) -> Entity
pub fn spawn<B: Bundle + 'static>(&self, bundle: B) -> Entity
Queue a spawn of bundle in this scope and return its handle.
The handle is reserved now and refers to a live entity once the queue is
applied. Its name comes from the bundle: a type of the caller’s own names
it after itself, and a bundle! after the source position that wrote the
bundle, so a queued spawn names the code that wrote the bundle rather
than the place that queued it.
Sourcepub fn spawn_named<B: Bundle + 'static>(
&self,
name: &'static str,
bundle: B,
) -> Entity
pub fn spawn_named<B: Bundle + 'static>( &self, name: &'static str, bundle: B, ) -> Entity
Queue a spawn of bundle in this scope under name.
Commands::spawn names the entity after the bundle itself; this is for
the objects whose name has to say more than that does.
Sourcepub fn despawn(&self, entity: Entity)
pub fn despawn(&self, entity: Entity)
Queue the despawn of entity and its subtree.
A refusal is answered when the queue is applied, not when it is
filled: the queue is filled from a callback that holds a shared world
and has nobody to answer, and the scope it was filled from is the only
thing it can say about ownership. World::apply reports the first
refusal it meets and keeps going.
Sourcepub fn link(&self, child: Entity, parent: Entity)
pub fn link(&self, child: Entity, parent: Entity)
Queue a relink of child into parent.
The refusal is answered when the queue is applied: both ends have to
be the queueing scope’s to move, nobody moves a root or the shared
scope itself, and no relink may hang a scope under its own child.
World::apply reports the first refusal it meets and keeps going.
Sourcepub fn unlink(&self, child: Entity)
pub fn unlink(&self, child: Entity)
Queue a detach of child into this queue’s scope.
The refusal is answered when the queue is applied: an entity in the
shared subtree moves only for the root, and the queueing scope may
only detach what it owns. Detaching what is already here is the thing
asked for, so it is answered with Ok(()).
Sourcepub fn push<C: Command + CommandErase>(&self, command: C)
pub fn push<C: Command + CommandErase>(&self, command: C)
Queue a command.