Crate structecs

Crate structecs 

Source
Expand description

§structecs

A flexible entity-component framework without the System.

§Overview

structecs provides an ECS-inspired data management system that focuses on flexibility over rigid System architecture. It allows you to:

  • Store hierarchical component data naturally
  • Query components efficiently using archetype-based storage
  • Extract components dynamically at runtime
  • Write game logic however you want (no forced System pattern)

§Example

use structecs::*;

#[derive(Debug, Extractable)]
pub struct Entity {
    pub name: String,
}

#[derive(Debug, Extractable)]
#[extractable(entity)]
pub struct Player {
    pub entity: Entity,
    pub health: u32,
}

let mut world = World::default();

let player = Player {
    entity: Entity {
        name: "Hero".to_string(),
    },
    health: 100,
};

let player_id = world.add_entity(player);

// Iterator-based query (efficient, no allocation)
for (id, entity) in world.query::<Entity>() {
    println!("Entity: {:?}", *entity);
}

// Extract specific component
if let Ok(health) = world.extract_component::<u32>(&player_id) {
    println!("Health: {}", *health);
}

Structs§

Acquirable
A smart pointer to a component that keeps the entity data alive.
ComponentHandler
A component handler that enables polymorphic behavior on entity hierarchies.
EntityId
Unique identifier for an entity in the World.
World
The central storage for all entities and their components.

Enums§

ExtractionMetadata
Metadata describing how to extract types from an entity structure.
WorldError
Errors that can occur when interacting with the World.

Traits§

Extractable
Trait for types that can be extracted from entity data.

Derive Macros§

Extractable