Rustic Entity-Component System
Simple entity-component system in pure Rust. Type reflection - no macros!
Install
Visit the crates.io page, and add the
specified line ("recs = ...
") to the [dependencies]
section of your
Cargo.toml. From then on, cargo build
should automatically download and compile
Rustic ECS.
Documentation
https://andybarron.github.io/rustic-ecs
Example
extern crate recs;
use recs::{Ecs, EntityId};
#[derive(Clone, PartialEq, Debug)]
struct Age{years: u32}
#[derive(Clone, PartialEq, Debug)]
struct Iq{points: i32}
fn main() {
let mut system: Ecs = Ecs::new();
let forrest: EntityId = system.create_entity();
let _ = system.set(forrest, Age{years: 22});
let _ = system.set(forrest, Iq{points: 75});
let age = system.get::<Age>(forrest).unwrap();
assert_eq!(age.years, 22);
let iq: Iq = system.get(forrest).unwrap();
assert_eq!(iq.points, 75);
let older = Age{years: age.years + 1};
let _ = system.set(forrest, older);
system.borrow_mut::<Iq>(forrest).map(|iq| iq.points += 5);
assert_eq!(system.borrow::<Age>(forrest), Ok(&Age{years: 23}));
assert_eq!(system.get::<Iq>(forrest), Ok(Iq{points: 80}));
}
License
MIT. Hooray!
(See LICENSE.txt
for details.)