[][src]Crate kudo

A simple and predictable Entity Component System.

An entity-component-system (ECS) is a data structure and organizational pattern often used by game-like code.

An ECS is made up of three parts:

  • Entities: IDs associated with various components
  • Components: Individual units of data associated with an entity.
  • Systems: Code that iterates over components
// First we create the world.
let mut world = World::new();

// Let's create a new entity with a name and a health component.
// Components are just plain structs.

// This will be our health component
struct Health(i32);

// Spawn the entity with a String component we'll use for the name and a Health component.
// Within the call to spawn we pass in a tuple that can have multiple components.
world.spawn(("Medusa".to_string(), Health(-2)));

// Query the world for entities that have a String component and a Health component.
// The '&' before each component requests read-only access to the component.
// Using '&mut' would request write/read access for that component.
let mut query = world.query::<(&String, &Health)>().unwrap();

// Iterate over all the components we found and check if their health is less than 0.
for (name, health) in query.iter() {
    if health.0 < 0 {
        println!("{} has perished!", name);
    }
}

Structs

ChainedIterator

An iterator that iterates multiple iterators in a row

Entity

A handle to an entity within the world.

Query

Query for entities with specific components.

World

The world holds all components and associated entities.

WorldBorrowImmut

A read-only borrow from the world.

WorldBorrowMut

A write/read capable borrow from the world.

Zip

An iterator over multiple iterators at once.

Traits

ComponentBundle

A bundle of components

EntityQueryItem

A member of a Query, like &A or &mut A

EntityQueryParams

Parameters passed in as part of a Query.

System

A function that can be run as system by pulling in queries from the world.

SystemQuery

A query that can be passed into a System function.

WorldBorrow

A trait for data that has been borrowed from the world. Call iter to get an iterator over the data.