Crate simplecs

Crate simplecs 

Source
Expand description

ยงsimplecs

Crates.io Documentation License: MIT OR Apache-2.0

simplecs is a lightweight, zero-dependency Entity-Component System (ECS) for Rust.
It emphasizes simplicity, type-safety, and ergonomic querying.


ยงโœจ Features

  • โœ… Simple API โ€” no macro-heavy boilerplate
  • ๐Ÿง  Type-based querying with With<T> / Without<T>
  • ๐Ÿงฉ Dynamic component registration via ComponentStorageBuilder
  • ๐Ÿ”„ Uses TypeId + Any internally for type-erased buckets
  • ๐Ÿฆ€ Pure safe Rust โ€” great for learning ECS

ยง๐Ÿš€ Example

use simplecs::*;
W
struct Position(f32, f32);
impl Component for Position {}

struct Velocity(f32, f32);
impl Component for Velocity {}

// For now, you should manually inform 
// how many combinations you can use in
// your queries
component_list!(A, B, C, D, E);

fn main() {
    let mut storage = ComponentStorageBuilder::<u32>::new()
        .with::<Position>()
        .with::<Velocity>()
        .build();

    storage.add_component(1, Position(1.0, 2.0));
    storage.add_component(1, Velocity(0.1, 0.1));
    storage.add_component(2, Position(5.0, 5.0));

    let moving = storage.query::<With<(Position, Velocity)>>();
    assert_eq!(moving, vec![1]);

    let static_entities = storage.query::<(With<Position>, Without<Velocity>)>();
    assert_eq!(static_entities, vec![2]);
}

ยง๐Ÿ“ Query API

simplecs uses type-safe static dispatch to query entities:

  • With<T> โ€“ selects entities with components T
  • Without<T> โ€“ selects entities that lack T
  • Combinations like (With<A>, Without<B>) work too

Define component groups with a macro:

component_list!(A, B, C, D, E, F);

Then use in queries:

let ids = storage.query::<(With<(Position, Velocity)>, Without<Health>)>();

ยง๐Ÿงฑ Architecture

  • Each component type has a separate Storage<E, T>
  • All storages are type-erased into dyn ComponentBucket<E>
  • ECS queries are resolved using sets and intersections
  • Entities can be any Copy + Eq + Hash type (e.g. u32)

ยง๐Ÿ›  License

Licensed under either of:


ยง๐Ÿฆ€ Created by Buzzac

For questions, ideas, or contributions, feel free to open an issue or PR.

Want to regenerate this README from your docs?

cargo install cargo-readme
cargo readme > README.md

Macrosยง

component_list

Structsยง

ComponentStorage
Storage
With
Without

Traitsยง

Component
ComponentBucket
ComponentList
Query

Derive Macrosยง

Component