#ecs #macro #tiny #nano #advancedresearch


A bare-bones macro-based Entity-Component-System

12 releases (breaking)

0.9.0 Aug 29, 2020
0.7.0 Aug 27, 2020

#2119 in Rust patterns

39 downloads per month


514 lines


A bare-bones macro-based Entity-Component-System

  • Maximum 64 components per entity
  • Stores components sequentially in same array
  • Masks for enabled/disabled components
use nano_ecs::*;

pub struct Position(pub f32);
pub struct Velocity(pub f32);

ecs!{4: Position, Velocity}

fn main() {
    let mut world = World::new();
    world.push((Position(0.0), Velocity(0.0)));
    let dt = 1.0;
    system!(world, |pos: &mut Position, vel: &Velocity| {
        pos.0 = pos.0 + vel.0 * dt;


The ecs! macro generates a World and Component object.

Can be used with any Rust data structure that implements Clone.

The order of declared components is used to assign every component an index. This index is used in the mask per entity and to handle slice memory correctly.

  • All components are stored in one array inside World.
  • All entities have a slice refering to components
  • All entities have a mask that enable/disable components

No runtime deps