ecs-tiny 0.4.0

A minimal ECS supporting entity and component insertion/removal, association, and single-type iteration.
Documentation

ecs-tiny

crates.io doc.rs

A minimal ECS supporting entity and component insertion/removal, association, and single-type iteration.

Usages

// Define an component:

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, bytemuck::Pod, bytemuck::Zeroable)]
pub struct ComponentA(i32);
impl ecs_tiny::Component for ComponentA {}

// Create new ecs instance and inserts new entity:

let mut world = ecs_tiny::World::new();

let entity_key0 = world.insert_entity();
let entity_key1 = world.insert_entity();

// Inserts new component associated with specified entity:

assert_eq!(world.insert_component(entity_key0, ComponentA(42)), Some(()));
assert_eq!(world.insert_component(entity_key1, ComponentA(63)), Some(()));

// Iterates over all components of specified type (single type only):

for ComponentA(value) in world.iter_component_mut::<ComponentA>() {
    *value += 1;
}

// Removes specified component:

world.remove_component::<ComponentA>(entity_key0).unwrap();

// Removes specified entity:

world.remove_entity(entity_key1).unwrap();