pub struct World { /* fields omitted */ }
Expand description
The ECS world storing Entities and components.
Create an Entity without any components.
To add components, see Self::insert().
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().
let mut world = World::new();
let entity = world.alloc();
world.insert(entity, (42_u32, true));
world.free(entity);
Insert components for a given Entity.
Panics if one of the components is already present for the entity.
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.
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();
Check if a given Entity exists.
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.
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.
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.
let mut world = World::new();
let entity = world.alloc();
world.insert(entity, (42_u32, true));
let comp = world.get_mut::<u32>(entity).unwrap();
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
The type returned in the event of a conversion error.
The type returned in the event of a conversion error.