Crate hecs

source ·
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

Structs

Enums

Traits

  • A statically typed collection of components
  • Types that can be components, implemented automatically for all Send + Sync + 'static types
  • &T or &mut T where T is some component type
  • &T where T 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