checs 0.2.0

An Entity-Component-System library.
Documentation
# checs

An Entity-Component-System library.

## Example

This is a very basic example of how to use `checs`.

You can find this example at `examples/basic.rs`. Run it with:

```sh
cargo run --example basic
```

---

Define some components and a `World` to store them in.

> Note: Components are just plain old Rust types.

```rust
struct Position { x: u32, y: u32, }
struct Health(i32);
struct Visible;

checs::impl_storage!(
    struct Storage {
        positions: Position,
        healths: Health,
        visibles: Visible,
    }
);

let mut world = world::World::<Storage>::new();
```

Create entities with initial components.

```rust
let player = world.spawn();
world.put(player, Health(80));
world.put(player, Position { x: 0, y: 0 });
world.put(player, Visible);

let obstacle = world.spawn();
world.put(obstacle, Position { x: 1, y: 1 });
world.put(obstacle, Visible);

let trap = world.spawn();
world.put(trap, Position { x: 2, y: 1 });

let enemy = world.spawn();
world.put(enemy, Health(100));
world.put(enemy, Position { x: 1, y: 4 });
world.put(enemy, Visible);
```

Find the entities that have some components.

```rust
use checs::iter::LendingIterator;
use checs::query::Join;

let ps = &world.storage.positions;
let vs = &world.storage.visibles;

let mut query = (ps, vs).join();

while let Some((e, p, h, v)) = query.next() {
    h.0 = h.0 - 17;
    println!("{e:?} is {v:?} at ({}, {})", p.x, p.y);
}

// Entity(0) is Visible at (0, 0)
// Entity(1) is Visible at (1, 1)
// Entity(3) is Visible at (1, 4)
```