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);
Modules
- Convenience tools for serializing
World
s
Structs
- A collection of entities having the same component types
- Shared reference to a single column of component data in an
Archetype
- Unique reference to a single column of component data in an
Archetype
- Determines freshness of information derived from
World::archetypes
- A sequence of entities yielded by
BatchedIter
- Error indicating that a
ColumnBatchBuilder
was missing components - Handle for appending components
- Batched version of
QueryIter
- A collection of components that implement
Clone
- A collection of component data for entities with the same component types
- An incomplete collection of component data for entities with the same component types
- A collection of component types
- Records operations for future application to a
World
- Lightweight unique ID, or handle, of an entity
- Helper for incrementally constructing a bundle of components with dynamic component types
- Variant of
EntityBuilder
that clones components on use - Handle to an entity with any component types
- Iterator over all of a world’s entities
- Error indicating that an entity did not have a required component
- Error indicating that no entity with a particular ID exists
- A prepared query can be stored independently of the
World
to amortize query set-up costs. - Combined borrow of a
PreparedQuery
and aWorld
- Iterates over all entities matching a
PreparedQuery
- Provides random access to the results of a prepared query
- A borrow of a
World
sufficient to execute the queryQ
- Iterator over the set of entities with the components in
Q
- A query builder that’s convertible directly into an iterator
- A borrow of a
World
sufficient to execute the queryQ
on a single entity - Shared borrow of an entity’s component
- Unique borrow of an entity’s component
- A query that matches all entities, yielding
bool
s indicating whether each satisfies queryQ
- Entity IDs created by
World::spawn_batch
- Iterator over
Entity
s spawned byWorld::spawn_column_batch()
- An entity removed from a
World
- Provides random access to the results of a query
- Transforms query
Q
by skipping entities not satisfying queryR
- Transforms query
Q
by skipping entities satisfying queryR
- An unordered collection of entities, each having any number of distinctly typed components
Enums
- Errors that arise when accessing components
- Holds an
L
, or anR
, or both - Errors that arise when querying a single entity
Traits
- A statically typed collection of components
- Types that can be components, implemented automatically for all
Send + Sync + 'static
types &T
or&mut T
whereT
is some component type&T
whereT
is some component type- A dynamically typed collection of components
- A dynamically typed collection of cloneable components
- A collection of component types to fetch from a
World
- Marker trait indicating whether a given
Query
will not produce unique references
Derive Macros
- Implement
Bundle
for a struct - Implement
DynamicBundleClone
for a struct. - Implement
Query
for a struct