Skip to main content

ScopeMut

Struct ScopeMut 

Source
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: Entity

Implementations§

Source§

impl<'w> ScopeMut<'w>

Source

pub(crate) fn new(world: &'w mut World, scope: Entity) -> Self

Source

pub fn entity(&self) -> Entity

The entity this scope is rooted at.

Source

pub fn as_scope(&self) -> Scope<'_>

The read-only form of this scope.

Source

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.

Source

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.

Source

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.

Source

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.

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.

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.

Source

pub fn scope_mut( &mut self, scope: Entity, ) -> Result<ScopeMut<'_>, EntityAccessError>

The mutable scope of a visible scope.

Source

pub fn apply(&mut self) -> Result<(), EntityAccessError>

Apply every queued command.

See World::apply for what a failing command is answered with.

Auto Trait Implementations§

§

impl<'w> !RefUnwindSafe for ScopeMut<'w>

§

impl<'w> !Send for ScopeMut<'w>

§

impl<'w> !Sync for ScopeMut<'w>

§

impl<'w> !UnwindSafe for ScopeMut<'w>

§

impl<'w> Forget for ScopeMut<'w>

§

impl<'w> Freeze for ScopeMut<'w>

§

impl<'w> Unpin for ScopeMut<'w>

§

impl<'w> UnsafeUnpin for ScopeMut<'w>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> Component for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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.

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more