Struct rs_ecs::World[][src]

pub struct World { /* fields omitted */ }
Expand description

The ECS world storing Entities and components.

Implementations

Create an empty world.

Create an Entity without any components. To add components, see Self::insert().

Example

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (42_u32, true));

Remove an Entity and all its components from the world. To remove components, see Self::remove().

Example

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (42_u32, true));

world.free(entity);

Remove all entites and their components from the world.

Insert components for a given Entity.

Panics

Panics if one of the components is already present for the entity.

Example

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (42_u32, true));
world.insert(entity, (String::from("Hello"),));

Remove components for a given Entity.

Example

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (42_u32, true, String::from("Hello")));

world.remove::<(u32, bool)>(entity).unwrap();
world.remove::<(String,)>(entity).unwrap();

Transfer an Entity and its components from this world to another.

Example

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (23_i32, false, String::from("Goodbye")));

let mut another_world = World::new();
let entity = world.transfer(entity, &mut another_world);

let comp = another_world.get::<String>(entity).unwrap();
assert_eq!(&*comp, "Goodbye");

Check if a given Entity exists.

Example

let mut world = World::new();

let entity = world.alloc();
assert!(world.exists(entity));

world.free(entity);
assert!(!world.exists(entity));

Check if a certain component type is present for an Entity.

Example

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (42_u32, true));

assert!(world.contains::<u32>(entity));

Get an immutable reference to the component of the given type for an Entity.

Note that for repeated calls, map can be used to amortize the set-up costs.

Example

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (42_u32, true));

let comp = world.get::<u32>(entity).unwrap();

Get a mutable reference to the component of the given type for an Entity.

Note that for repeated calls, map can be used to amortize the set-up costs.

Example

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (42_u32, true));

let comp = world.get_mut::<u32>(entity).unwrap();

Trait Implementations

Create an empty world.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.