Expand description
A handy ECS
hecs provides a high-performance, minimalist entity-component-system (ECS) world. It is a
library, not a framework. In place of an explicit “System” abstraction, a World’s entities are
easily queried from regular code. Organize your application however you like!
In order of importance, hecs pursues:
- fast traversals
- a simple interface
- a small dependency closure
- exclusion of externally-implementable functionality
let mut world = World::new();
// Nearly any type can be used as a component with zero boilerplate
let a = world.spawn((123, true, "abc"));
let b = world.spawn((42, false));
// Systems can be simple for loops
for (id, (number, &flag)) in world.query_mut::<(&mut i32, &bool)>() {
if flag { *number *= 2; }
}
// Random access is simple and safe
assert_eq!(*world.get::<i32>(a).unwrap(), 246);
assert_eq!(*world.get::<i32>(b).unwrap(), 42);Structs§
- Archetype
- A collection of entities having the same component types
- Archetypes
Generation - Determines freshness of information derived from
World::archetypes - Batch
- A sequence of entities yielded by
BatchedIter - Batch
Incomplete - Error indicating that a
ColumnBatchBuilderwas missing components - Batch
Writer - Handle for appending components
- Batched
Iter - Batched version of
QueryIter - Built
Entity - The output of an
EntityBuilder, suitable for passing toWorld::spawnorWorld::insert - Cloneable
- Type parameter for
EntityBuilders with cloneable components - Column
Batch - A collection of component data for entities with the same component types
- Column
Batch Builder - An incomplete collection of component data for entities with the same component types
- Column
Batch Type - A collection of component types
- Dynamic
Component - A handle to a component of type
Treturned from a dynamic query, obtained byDynamicItem::take. - Dynamic
Item - A set of components returned from some dynamic query, which belong to some entity satisfying that query.
- Dynamic
Item Ref - Immutable borrow of a
DynamicComponent. - Dynamic
Item RefMut - Mutable borrow of a
DynamicComponent. - Dynamic
Query - A dynamic query; the dynamic equivalent of the
Querytrait. Used withWorld::dynamic_queryandWorld::dynamic_query_one. - Dynamic
Query Borrow - A borrow of a
Worldsufficient to execute some dynamic query. - Dynamic
Query Iter - Iterator over the set of entities which satisfy some
DynamicQuery. - Dynamic
With - A dynamic query transformer which requires that entities satisfying some dynamic query also have some component type, without needing to borrow it.
- Dynamic
Without - A dynamic query transformer which requires that entities satisfying the subquery also not contain some component type.
- Entity
- Lightweight unique ID, or handle, of an entity
- Entity
Builder - Helper for incrementally constructing a bundle of components with dynamic component types
- Entity
Ref - Handle to an entity with any component types
- Iter
- Iterator over all of a world’s entities
- Missing
Component - Error indicating that an entity did not have a required component
- NoSuch
Entity - Error indicating that no entity with a particular ID exists
- Prepared
Query - A prepared query can be stored independently of the
Worldto amortize query set-up costs. - Prepared
Query Borrow - Combined borrow of a
PreparedQueryand aWorld - Prepared
Query Iter - Iterates over all entities matching a
PreparedQuery - Query
Borrow - A borrow of a
Worldsufficient to execute the queryQ - Query
Iter - Iterator over the set of entities with the components in
Q - Query
Mut - A query builder that’s convertible directly into an iterator
- Query
One - A borrow of a
Worldsufficient to execute the queryQon a single entity - Ref
- Shared borrow of an entity’s component
- RefMut
- Unique borrow of an entity’s component
- Reusable
Built Entity - A collection of components that implement
Clone - Satisfies
- A query that yields
trueiff an entity would satisfy the queryQ - Spawn
Batch Iter - Entity IDs created by
World::spawn_batch - Spawn
Column Batch Iter - Iterator over
Entitys spawned byWorld::spawn_column_batch() - With
- Query transformer skipping entities that do not have a
Tcomponent - Without
- Query transformer skipping entities that have a
Tcomponent - World
- An unordered collection of entities, each having any number of distinctly typed components
Enums§
- Access
- Type of access a
Querymay have to anArchetype - Component
Error - Errors that arise when accessing components
- Or
- Holds an
L, or anR, or both - Query
OneError - Errors that arise when querying a single entity
Traits§
- Bundle
- A statically typed collection of components
- Component
- Types that can be components, implemented automatically for all
Send + Sync + 'statictypes - Dynamic
Bundle - A dynamically typed collection of components
- Query
- A collection of component types to fetch from a
World
Type Aliases§
- Query
Item - Type of values yielded by a query