pub struct WorldRef { /* private fields */ }Expand description
A reference to a World with erased lifetime for ergonomic entity traversal.
This is the single unsafe boundary in the crate. All EntityPtr instances
created from a WorldRef will borrow from the original World.
§Size
8 bytes (&'static World)
§Safety
The caller must ensure:
- The World outlives all
EntityPtrinstances created from thisWorldRef - The World is NOT mutated while any
EntityPtrexists
In Bevy systems, this is naturally satisfied: systems with &World access
cannot mutate. Create WorldRef at system entry, use it for reads, and let
it drop before the system returns.
For stale reference handling across mutations, use EntityHandle instead.
§Thread Safety
NOT Send, NOT Sync - must stay on the creating thread within a single system.
Implementations§
Source§impl WorldRef
impl WorldRef
Sourcepub unsafe fn new(world: &World) -> Self
pub unsafe fn new(world: &World) -> Self
Creates a new WorldRef by transmuting the lifetime to ’static.
§Safety
The caller must ensure that:
- The World reference outlives all
EntityPtrinstances created from thisWorldRef - The World is NOT mutated while any
EntityPtrfrom thisWorldRefexists - Typically this means the
WorldRefis created at system entry and discarded at system exit
Sourcepub fn entity(&self, entity: Entity) -> EntityPtr
pub fn entity(&self, entity: Entity) -> EntityPtr
Gets an EntityPtr for the given entity.
Returns an EntityPtr regardless of whether the entity exists.
Use EntityPtr::is_alive() to check validity.
Sourcepub fn entity_opt(&self, entity: Entity) -> Option<EntityPtr>
pub fn entity_opt(&self, entity: Entity) -> Option<EntityPtr>
Gets an EntityPtr only if the entity exists.
Returns None if the entity has been despawned.
Sourcepub fn from_handle(&self, handle: EntityHandle) -> EntityPtr
pub fn from_handle(&self, handle: EntityHandle) -> EntityPtr
Creates an EntityPtr from an EntityHandle.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WorldRef
impl !RefUnwindSafe for WorldRef
impl Send for WorldRef
impl Sync for WorldRef
impl Unpin for WorldRef
impl !UnwindSafe for WorldRef
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.