| Crates.io | sunflowerecs |
| lib.rs | sunflowerecs |
| version | 2.1.0 |
| created_at | 2025-09-30 02:28:16.232918+00 |
| updated_at | 2025-10-18 15:16:57.074265+00 |
| description | A hybrid ECS library written in Rust. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1860486 |
| size | 22,480 |
SunflowerECS-Rust is a hybrid ECS library designed for use in Rust applications.
It's based on my https://github.com/JaydonXOneGitHub/SunflowerECS library, which was made in C#.
Install the library, either by using cargo add sunflowerecs or by manually copying the repo and linking to it.
To use:
use sunflowerecs::{
behavioursystem::BehaviourSystem, componentcollection::ComponentCollection, scene::Scene,
tbehaviourcomponent::TBehaviourComponent, tcomponent::TComponent,
};
pub struct Position {
pub x: f64,
pub y: f64,
}
impl TComponent for Position {}
fn main() {
let scene_rc = Scene::new();
let scene: &mut Scene = scene_rc.get_mut().unwrap();
scene.add_system(BehaviourSystem::new());
let rc = scene.create_entity(&scene_rc);
if let Option::Some(entity) = rc.get_mut() {
let mut coll: ComponentCollection<Position> = ComponentCollection::new();
coll.add(Position { x: 0.0, y: 0.0 });
assert!(!coll.get_entity().is_some());
assert!(
entity
.add_component::<ComponentCollection<Position>>(coll)
.is_some()
);
entity.add_component(Position { x: 80.0, y: 63.1 });
assert!(
entity
.use_component(|coll: &mut ComponentCollection<Position>| {
coll.add(Position { x: 5.3, y: 23.8 });
assert_eq!(coll.size(), 2);
})
.is_some()
);
}
}