pub struct World { /* private fields */ }
Expand description
The world storing entities and their components.
Implementations
sourceimpl World
impl World
sourcepub fn alloc(&mut self) -> Entity
pub fn alloc(&mut self) -> Entity
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));
sourceimpl World
impl World
sourcepub fn exchange<B1, B2>(&mut self, ent: Entity, new_comps: B2) -> Option<B1> where
B1: Bundle,
B2: Bundle,
pub fn exchange<B1, B2>(&mut self, ent: Entity, new_comps: B2) -> Option<B1> where
B1: Bundle,
B2: Bundle,
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));
sourceimpl World
impl World
sourcepub fn transfer(&mut self, ent: Entity, other: &mut World) -> Entity
pub fn transfer(&mut self, ent: Entity, other: &mut World) -> 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");
sourceimpl World
impl World
sourcepub fn get<C>(&self, ent: Entity) -> Option<Comp<'_, C>> where
C: 'static,
pub fn get<C>(&self, ent: Entity) -> Option<Comp<'_, C>> where
C: 'static,
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();
sourcepub fn get_mut<C>(&self, ent: Entity) -> Option<CompMut<'_, C>> where
C: 'static,
pub fn get_mut<C>(&self, ent: Entity) -> Option<CompMut<'_, C>> where
C: 'static,
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
Auto Trait Implementations
impl !RefUnwindSafe for World
impl !Send for World
impl !Sync for World
impl Unpin for World
impl UnwindSafe for World
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more