World

The world holds the entities and components in the ECS.

#![allow(unused)]
fn main() {
    let mut world = World::new();
}

Spawning an entity yields an Entity id.

#![allow(unused)]
fn main() {
    let id = world.spawn();

    if world.is_alive(id) {
        println!("It is alive!");
    }
}

When an entity is despawned, it can no longer be accessed.

Entity ids are versioned, which means that once an entity is despawned the index in the storage may be reused, but it will have a different version, which prevents dead entities to become alive at a later point in time. I.e; dead entities stay dead, this is not a zombie apocalypse we are working with.

#![allow(unused)]
fn main() {
    world.despawn(id)?;

    if world.is_alive(id) {
        println!("We've got a zombie on our hands");
    }

}

Many entities can be spawned at a time, which is easily demonstrated by this iterator which takes entity ids from the world

#![allow(unused)]
fn main() {
    let ids = world.spawn_many().take(10).collect_vec();
    println!("ids: {ids:?}");
}