Expand description
Original, dependency-free entity/component storage for small Ferravex games.
Components live in one sparse, contiguous slot array per Rust type. Entity
generations prevent stale handles from reaching reused slots. Iteration visits
live entity slots in stable order. Runtime component borrowing uses standard
library Ref / RefMut guards, so overlapping queries cannot create
aliased mutable references, even if an iterator is retained or abandoned.
use ferravex_ecs::{Entity, World};
let mut world = World::new();
let player = world.spawn((10_i32, 2.0_f32));
for (entity, mut health, speed) in &mut world.query::<(Entity, &mut i32, &f32)>() {
assert_eq!(entity, player);
*health += *speed as i32;
}
assert_eq!(*world.get::<&i32>(player).unwrap(), 12);
world.despawn(player).unwrap();
assert!(!world.contains(player));Query results are borrow guards rather than naked references. Bind mutable
results with mut, as above. try_query and try_iter report conflicts as
errors; query and iter panic on invalid/overlapping borrows. Structural
operations require &mut World, so Rust prevents them while guards exist.
ⓘ
use ferravex_ecs::World;
let mut world = World::new();
let entity = world.spawn((42_i32,));
let component = world.get::<&i32>(entity).unwrap();
world.despawn(entity).unwrap(); // A live guard borrows the world.
println!("{}", *component);Structs§
- All
- Conjunction of a tuple of zero to four filters; groups may nest.
All<()>matches every live entity. SeeWorld::query_filtered. - Any
- Disjunction of a tuple of zero to four filters; groups may nest.
Any<()>matches no entities. SeeQueryFilterfor a runnable example. - Duplication
Plan - Owned snapshot of explicitly selected components for
Ndistinct sources. - Entity
- Opaque slot identity. A despawned entity never becomes valid again in its world. Handles are world-local; two separate worlds may issue the same identity.
- Not
- Negation of one filter within live entities. See
QueryFilter. - Query
Borrow - Query
Iter - Ref
- Wraps a borrowed reference to a value in a
RefCellbox. A wrapper type for an immutably borrowed value from aRefCell<T>. - RefMut
- A wrapper type for a mutably borrowed value from a
RefCell<T>. - TryQuery
Iter - With
- Presence of component
T, without borrowing its value. Used as a type argument; seeWorld::query_filteredfor a runnable example. - Without
- Absence of component
T, without borrowing any value. Used as a type argument; seeQueryFilterfor a runnable example. - World
- Sparse typed storage with generational entities and checked component borrows.
Enums§
- Duplication
Error - Failure to read an explicit selected-component duplication plan.
- Error
- Spawn
Error - Failure to prepare storage or preflight a bounded spawn batch.
Traits§
- Access
- A required (
&T,&mut T) or optional (Option<&T>,Option<&mut T>) component access, or the entity identity itself. - Bundle
- Tuple of zero to eight owned component values accepted by spawn and insert. Implementations are sealed so validation and insertion cannot disagree. Duplicate types are rejected before any entity allocation or component write. Validation uses bounded stack metadata; entity and component storage may allocate.
- Clone
Bundle - Explicit tuple of zero to eight owned
Clone + 'staticcomponent types. - Query
- Query signature: one access type or a tuple of one to eight access types.
Each
Entitycounts as an entry. Filter clauses have their own separate four-clause group bound; seeQueryFilter. SeeBundlefor an actor system. - Query
Filter - A sealed structural component-presence predicate for
World::query_filtered.