pub struct ScopeMut<'w> {
world: &'w mut World,
scope: Entity,
}Expand description
A mutable scope: one entity and everything below it.
Fields§
§world: &'w mut World§scope: EntityImplementations§
Source§impl<'w> ScopeMut<'w>
impl<'w> ScopeMut<'w>
pub(crate) fn new(world: &'w mut World, scope: Entity) -> Self
Sourcepub fn spawn<B: Bundle>(&mut self, bundle: B) -> Entity
pub fn spawn<B: Bundle>(&mut self, bundle: B) -> Entity
Spawn bundle in this scope.
The entity is named after the bundle, which is what its Debug prints:
a type of the caller’s own names it after itself, and a bundle! after
the source position that wrote it. A dynamic bundle put together by hand
carries no name, so an entity spawned from one has none; build it with
DynamicBundle::named, or spawn it with ScopeMut::spawn_named.
Sourcepub fn spawn_named<B: Bundle>(
&mut self,
name: &'static str,
bundle: B,
) -> Entity
pub fn spawn_named<B: Bundle>( &mut self, name: &'static str, bundle: B, ) -> Entity
Spawn bundle in this scope under name, whatever the bundle was
built from.
ScopeMut::spawn names the entity after the bundle itself, so this is
for the objects whose name has to say more than that does.
Sourcepub fn spawn_at<B: Bundle>(
&mut self,
entity: Entity,
bundle: B,
) -> Result<(), EntityAccessError>
pub fn spawn_at<B: Bundle>( &mut self, entity: Entity, bundle: B, ) -> Result<(), EntityAccessError>
Spawn bundle on entity, a handle from World::reserve_entity.
Answers EntityAccessError::NotReserved when the handle is not a live
reservation: it has already been spawned on, was released, or was never
reserved to begin with.
Sourcepub fn despawn(&mut self, entity: Entity) -> Result<usize, EntityAccessError>
pub fn despawn(&mut self, entity: Entity) -> Result<usize, EntityAccessError>
Despawn entity and its whole subtree, answering how many entities
the despawn took with it.
Children are removed before the parent they lived in, so a child’s despawn callback still sees living ancestors.
Answers EntityAccessError::NotAlive for a handle that names no live
entity, NotOwned for one outside this scope’s subtree, NotMovable
for one the shared subtree only lends this scope - the root is the
scope that may remove it - and Scaffolding for the root and the
shared scope themselves.
Sourcepub fn link(
&mut self,
child: Entity,
parent: Entity,
) -> Result<(), EntityAccessError>
pub fn link( &mut self, child: Entity, parent: Entity, ) -> Result<(), EntityAccessError>
Make child a child of parent.
Both must be owned by this scope, neither may be a root or the shared
scope, and parent may not be inside child’s subtree. An entity in
the shared subtree is the root’s to move, so only a root scope relinks
it.
The same errors as ScopeMut::despawn, plus
EntityAccessError::WouldCycle when parent is child itself or
sits inside its subtree: that move would cut the tree in two.
Sourcepub fn unlink(&mut self, child: Entity) -> Result<(), EntityAccessError>
pub fn unlink(&mut self, child: Entity) -> Result<(), EntityAccessError>
Detach child from its parent and put it in this scope.
An entity already in this scope has nowhere to move to, and that is
answered with Ok(()) rather than an error: what the caller asked for
is already true.
The same errors as ScopeMut::despawn, plus
EntityAccessError::WouldCycle when child is this scope itself,
which would make it its own parent.
Sourcepub fn scope_mut(
&mut self,
scope: Entity,
) -> Result<ScopeMut<'_>, EntityAccessError>
pub fn scope_mut( &mut self, scope: Entity, ) -> Result<ScopeMut<'_>, EntityAccessError>
The mutable scope of a visible scope.
Sourcepub fn apply(&mut self) -> Result<(), EntityAccessError>
pub fn apply(&mut self) -> Result<(), EntityAccessError>
Apply every queued command.
See World::apply for what a failing command is answered with.