pub struct World { /* fields omitted */ }
Expand description
The ECS world storing Entity and components.
#[must_use]
pub fn alloc(&mut self) -> Entity
[src]
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);
pub fn insert<B>(&mut self, ent: Entity, comps: B) where
B: Bundle,
[src]
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"),));
pub fn remove<B>(&mut self, ent: Entity) -> Option<B> where
B: Bundle,
[src]
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();
pub fn contains<C>(&self, ent: Entity) -> bool where
C: 'static,
[src]
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));
pub fn get<C>(&self, ent: Entity) -> Option<Comp<'_, C>> where
C: 'static,
[src]
Get an immutable reference to the component of the given type for an Entity.
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.
let mut world = World::new();
let entity = world.alloc();
world.insert(entity, (42_u32, true));
let comp = world.get_mut::<u32>(entity).unwrap();
impl<T> Any for T where
T: 'static + ?Sized,
[src]
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
impl<T, U> Into<U> for T where
U: From<T>,
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
The type returned in the event of a conversion error.
The type returned in the event of a conversion error.