[][src]Crate bevy_hecs

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, mut number, &flag) in &mut world.query_mut::<(Entity, &mut i32, &bool)>() {
  if flag { *number *= 2; }
}
assert_eq!(*world.get::<i32>(a).unwrap(), 246);
assert_eq!(*world.get::<i32>(b).unwrap(), 42);

Macros

impl_query_set
smaller_tuples_too

Imagine macro parameters, but more like those Russian dolls.

Structs

Added

Query transformer that retrieves components of type T that have been added since the start of the frame.

Archetype

A collection of entities having the same component types

ArchetypeComponent
ArchetypesGeneration

Determines freshness of information derived from World::archetypes

AtomicBorrow

Atomically enforces Rust-style borrow checking at runtime

Batch

A sequence of entities yielded by BatchedIter

BatchedIter

Batched version of QueryIter

BuiltEntity

The output of an EntityBuilder, suitable for passing to World::spawn or World::insert

Changed

Query transformer that retrieves components of type T that have either been mutated or added since the start of the frame.

Entity

Lightweight unique ID of an entity

EntityBuilder

Helper for incrementally constructing a bundle of components with dynamic component types

EntityReserver

Reserves entities in a way that is usable in multi-threaded contexts.

Location

A location of an entity in an archetype

MissingComponent

Error indicating that an entity did not have a required component

Mut

Unique borrow of an entity's component

Mutated

Query transformer that retrieves components of type T that have been mutated since the start of the frame. Added components do not count as mutated.

NoSuchEntity

Error indicating that no entity with a particular ID exists

Or

Query transformer performing a logical or on a pair of queries Intended to be used on Mutated or Changed queries.

QueryIter

Iterator over the set of entities with the components in Q

Ref

Shared borrow of an entity's component

RefMut

Unique borrow of an entity's component

SpawnBatchIter

Entity IDs created by World::spawn_batch

TypeAccess

Provides information about the types a [System] reads and writes

TypeState

Metadata about a type stored in an archetype

With

Query transformer skipping entities that do not have a T component

Without

Query transformer skipping entities that have a T component

World

An unordered collection of entities, each having any number of distinctly typed components

Enums

ComponentError

Errors that arise when accessing components

QueryAccess

Traits

Bundle

A statically typed collection of components

Component

Types that can be components, implemented automatically for all Send + Sync + 'static types

DynamicBundle

A dynamically typed collection of components

Query

A collection of component types to fetch from a World

ReadOnlyFetch

A fetch that is read only. This should only be implemented for read-only fetches.

Derive Macros

Bundle

Implement Bundle for a monomorphic struct