Expand description
The world: entities, their components, and the scopes they live in.
Components live in UnsafeCells so that a shared &World can reach them,
and a borrow ledger written through that same shared reference catches two
access paths reaching one value when at least one of them writes. The world
is therefore !Send: it stays on the thread that created it, which is where
a renderer or any other !Send state lives.
Reading and writing components needs only &World. Structural changes –
spawning and despawning – need &mut World. A callback that only has a shared world can queue those
changes instead with crate::Commands and apply them later with
World::apply.
Every entity lives in a scope, and a scope is another entity: the one the
world’s tree says it lives in. The world therefore holds a tree, and the
entry points that read or write it are scopes of a scope rather than
methods on the world – Scope and ScopeMut. A scope sees
its own subtree and nothing beside it; only &World reaches the root.
An entity’s components are fixed when it is spawned; there is no way to add or remove one later. To change the set of components, despawn the entity and spawn a new one.
A borrow conflict is a panic, not a compile error: two claims the ledger
cannot share — a shared claim still held while a write asks for the same
component, or the same component fetched as &mut twice in one query —
report the component’s name and both claim sites, then stop. This is the
trade for not doing access analysis. An optional component is optional only
about the component being absent: a conflict over one the row does carry
panics as well.
Re-exports§
use core::any::TypeId;🔒use core::cell::Ref;🔒use core::cell::RefCell;🔒use core::cell::RefMut;🔒use std::collections::VecDeque;🔒use crate::archetype::Archetype;🔒use crate::archetype::Archetypes;🔒use crate::borrow::BorrowLedger;🔒use crate::borrow::Rows;🔒use crate::bundle::Bundle;🔒use crate::bundle::BundleComponent;🔒use crate::bundle::DynamicBundle;🔒use crate::column::AnyColumn;🔒use crate::command::Command;🔒use crate::entity::Entities;🔒use crate::entity::Entity;🔒use crate::entity::Location;🔒use crate::error::EntityAccessError;🔒use crate::hash::TypeIdHashMap;🔒use crate::lifecycle::Lifecycle;🔒use crate::lifecycle::LifecycleCallback;🔒use crate::query::Mode;🔒use crate::scope::ScopeTree;🔒use crate::view::Scope;🔒use crate::view::ScopeMut;🔒
Structs§
- World
- Entities and their components.
Type Aliases§
- Commands
Guard 🔒 - The exclusive borrow of a world’s command queue.