anvaya 0.1.0

ECS like dynamic storage in ~500 LOC.
Documentation
  • Coverage
  • 42.11%
    24 out of 57 items documented2 out of 2 items with examples
  • Size
  • Source code size: 43.97 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 796.21 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • nilaysavant/anvaya
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • nilaysavant

Anvaya

ECS like dynamic storage in ~500 LOC.

🚧 WIP toy project. Use at your own risk ⚠️

use anvaya::prelude::*;

// Create Components (of any type with no boilerplate)...
struct Player(&'static str);
struct Age(u8);

// World and spawn...
let mut world = World::new();
world.spawn().insert(Player("Mike")).insert(Age(30));
world.spawn().insert(Player("Hannah")).insert(Age(25));

// Query and filter...
let mut query = world.query();
let mut results = query
    .with::<Age>()
    .get::<Player>()
    .unwrap()
    .map(|(_, player)| player.0);

// Validate...
assert_eq!(results.next().unwrap(), "Mike");
assert_eq!(results.next().unwrap(), "Hannah");

Features

  • Simple implementation using the TypeMap data structure.
  • No unsafe, no Clone, no smart pointers/atomics. Just Box<dyn Any>.
  • Uses Slab as default tabular storage. But allows swapping it for your own custom storage by impl a few traits like Storage etc. See custom_storage.rs example.

The above features are subject to change based on the goals of the project.

Limitations

  • Does not strictly follow an ECS architecture (with Archetypes etc).
  • Currently supports only few methods and limited queries. Queries to get or mutate multiple components together are not yet supported.

Goals

  • Allow more ECS like queries and mutations in the future.
  • Thus follow a more ECS like architecture to achieve the above.

Motivations

  • Started as a toy project experimenting with dynamic storage in a strictly type safe language like Rust.
  • With the end goal of building an ECS like data structure, there were key learnings wrt Generic Types, Traits, and Lifetimes in Rust.
  • Type storage using Box<dyn Any> and type identifications using TypeID led to creation of data structures like TypeMap. This was the key inspiration to start this project.