pub struct World { /* private fields */ }Expand description
Sparse typed storage with generational entities and checked component borrows.
RefCell deliberately makes World !Sync. Parallel mutation should use separate worlds or explicit synchronization around the whole world.
Implementations§
Source§impl World
impl World
pub fn new() -> World
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn contains(&self, entity: Entity) -> bool
Sourcepub fn spawn<B>(&mut self, bundle: B) -> Entitywhere
B: Bundle,
pub fn spawn<B>(&mut self, bundle: B) -> Entitywhere
B: Bundle,
Spawns one entity containing zero to four components. Panics if a bundle repeats a component type; no entity is allocated in that case.
pub fn try_spawn<B>(&mut self, bundle: B) -> Result<Entity, Error>where
B: Bundle,
Sourcepub fn despawn(&mut self, entity: Entity) -> Result<(), Error>
pub fn despawn(&mut self, entity: Entity) -> Result<(), Error>
Drops every component and invalidates the handle before reusing its slot.
Sourcepub fn insert<B>(&mut self, entity: Entity, bundle: B) -> Result<(), Error>where
B: Bundle,
pub fn insert<B>(&mut self, entity: Entity, bundle: B) -> Result<(), Error>where
B: Bundle,
Inserts or replaces a bundle’s components. Other components remain unchanged. Invalid identities and duplicate bundle types are rejected before any writes.
pub fn remove<T>(&mut self, entity: Entity) -> Result<T, Error>where
T: 'static,
pub fn has<T>(&self, entity: Entity) -> boolwhere
T: 'static,
Sourcepub fn get<A>(&self, entity: Entity) -> Result<<A as Access>::Item<'_>, Error>where
A: Access,
pub fn get<A>(&self, entity: Entity) -> Result<<A as Access>::Item<'_>, Error>where
A: Access,
Reads or mutates a typed component through an explicit access type. Use get::<&T> or get::<&mut T>; returned guards enforce runtime aliasing.
pub fn get_mut<T>(&self, entity: Entity) -> Result<RefMut<'_, T>, Error>where
T: 'static,
Sourcepub fn query<Q>(&self) -> QueryBorrow<'_, Q>where
Q: Query,
pub fn query<Q>(&self) -> QueryBorrow<'_, Q>where
Q: Query,
Queries up to four component access types, optionally including Entity. Repeated shared access is valid; any repeated mutable access is rejected.