pub struct World { /* private fields */ }
Expand description
The world storing entities and their components.
Implementations
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);
Exchange components for a given Entity
Example
let mut world = World::new();
let entity = world.alloc();
world.insert(entity, (42_u32, true));
assert!(world.contains::<u32>(entity));
assert!(world.contains::<bool>(entity));
assert!(!world.contains::<String>(entity));
world.exchange::<(u32, bool), _>(entity, (String::from("Hello"),)).unwrap();
assert!(!world.contains::<u32>(entity));
assert!(!world.contains::<bool>(entity));
assert!(world.contains::<String>(entity));
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");
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();