Crate ferravex_ecs

Source
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. See World::query_filtered.
Any
Disjunction of a tuple of zero to four filters; groups may nest. Any<()> matches no entities. See QueryFilter for a runnable example.
DuplicationPlan
Owned snapshot of explicitly selected components for N distinct 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.
QueryBorrow
QueryIter
Ref
Wraps a borrowed reference to a value in a RefCell box. A wrapper type for an immutably borrowed value from a RefCell<T>.
RefMut
A wrapper type for a mutably borrowed value from a RefCell<T>.
TryQueryIter
With
Presence of component T, without borrowing its value. Used as a type argument; see World::query_filtered for a runnable example.
Without
Absence of component T, without borrowing any value. Used as a type argument; see QueryFilter for a runnable example.
World
Sparse typed storage with generational entities and checked component borrows.

Enums§

DuplicationError
Failure to read an explicit selected-component duplication plan.
Error
SpawnError
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.
CloneBundle
Explicit tuple of zero to eight owned Clone + 'static component types.
Query
Query signature: one access type or a tuple of one to eight access types. Each Entity counts as an entry. Filter clauses have their own separate four-clause group bound; see QueryFilter. See Bundle for an actor system.
QueryFilter
A sealed structural component-presence predicate for World::query_filtered.