yarecs

Yet Another Rust Entity Component System

3 releases

0.1.2 Sep 15, 2024
0.1.1 Sep 15, 2024
0.1.0 Sep 15, 2024
Download history 309/week @ 2024-09-12 75/week @ 2024-09-19 34/week @ 2024-09-26 18/week @ 2024-10-03

436 downloads per month

MIT license

21KB
325 lines

Yet Another Rust Entity Component System

yarecs is a simple and flexible implementation of an ecs in rust.

It's based on this article: How to make a simple entity-component-system in C++, but I had to make some changes to port it to rust.

No trait bounds for component types.

No limit on the number of component types.

No unsafe, no macros.

Should be reasonably fast and memory-efficient, but I haven't profiled it (yet).

Example code:

use yarecs::scene;

#[derive(Debug, Default)]
struct Position;
#[derive(Debug, Default)]
struct Velocity;

fn main() {
    let mut main_scene = scene::Scene::new();
    let entity = main_scene.create_entity();
    main_scene.assign_default::<Position>(entity).unwrap();
    main_scene.assign_default::<Velocity>(entity).unwrap();
    let mut entity_count = 0;
    for entity in main_scene.view::<(Position, (Velocity, ()))>() {
        println!("{:?}", entity);
        entity_count += 1;
    }
    println!("Entity count: {}", entity_count);
}

Dependencies

~10KB