pub struct FlowWorld { /* private fields */ }Expand description
World reference that is updated when flow is polled.
Implementations§
source§impl FlowWorld
impl FlowWorld
sourcepub unsafe fn get<'a>(self) -> &'a mut WorldLocal
pub unsafe fn get<'a>(self) -> &'a mut WorldLocal
Returns reference to currently bound world.
It is easy to accidentally create aliasing references to the world. Prefer to use safe methods provided on this type to interact with the world.
If access to WorldLocal is required, consider using FlowWorld::poll first.
§Safety
Creates reference from raw pointer to WorldLocal bound to the flow context.
Returned reference is unbound so it may outlive referenced world and become dangling.
Creating more than one mutable reference to the world may also cause undefined behavior.
Note that many methods of FlowWorld or FlowEntity
create temporary mutable references to the world.
So calling them while this reference is alive is not allowed.
sourcepub fn map<F, R>(self, f: F) -> Rwhere
F: FnOnce(&mut WorldLocal) -> R,
pub fn map<F, R>(self, f: F) -> Rwhere
F: FnOnce(&mut WorldLocal) -> R,
Access world reference with closure. Returns closure result.
Unlike FlowWorld::get this method is safe as it does not allow references to world to escape closure.
And therefore references won’t able to outlive await boundaries.
Use FlowWorld::poll if you need to call poll closure until certain condition is met.
sourcepub fn poll<F, R>(self, f: F) -> PollWorld<F> ⓘ
pub fn poll<F, R>(self, f: F) -> PollWorld<F> ⓘ
Returns a future that will poll the closure with world reference.
The future will resolve to closure result in Poll::Ready.
The closure may use task context to register wakers.
sourcepub fn poll_view<Q, F, R>(self, f: F) -> PollView<Q::Query, (), F> ⓘ
pub fn poll_view<Q, F, R>(self, f: F) -> PollView<Q::Query, (), F> ⓘ
Returns a future that will poll the closure with world view
constructed with specified query type.
The future will resolve to closure result in Poll::Ready.
The closure may use task context to register wakers.
sourcepub fn poll_view_filter<Q, F, Fun, R>(
self,
f: Fun,
) -> PollView<Q::Query, F::Query, Fun> ⓘ
pub fn poll_view_filter<Q, F, Fun, R>( self, f: Fun, ) -> PollView<Q::Query, F::Query, Fun> ⓘ
Returns a future that will poll the closure with world view
constructed with specified query type and filter type.
The future will resolve to closure result in Poll::Ready.
The closure may use task context to register wakers.
sourcepub fn poll_view_with<Q, F, R>(
self,
query: Q,
f: F,
) -> PollView<Q::Query, (), F> ⓘ
pub fn poll_view_with<Q, F, R>( self, query: Q, f: F, ) -> PollView<Q::Query, (), F> ⓘ
Returns a future that will poll the closure with world view
constructed with specified query.
The future will resolve to closure result in Poll::Ready.
The closure may use task context to register wakers.
sourcepub fn poll_view_filter_with<Q, F, Fun, R>(
self,
query: Q,
filter: F,
f: Fun,
) -> PollView<Q::Query, F::Query, Fun> ⓘ
pub fn poll_view_filter_with<Q, F, Fun, R>( self, query: Q, filter: F, f: Fun, ) -> PollView<Q::Query, F::Query, Fun> ⓘ
Returns a future that will poll the closure with world view
constructed with specified query and filter.
The future will resolve to closure result in Poll::Ready.
The closure may use task context to register wakers.
sourcepub fn entity(self, entity: EntityId) -> Result<FlowEntity, NoSuchEntity>
pub fn entity(self, entity: EntityId) -> Result<FlowEntity, NoSuchEntity>
Returns entity reference.
Returns NoSuchEntity error if entity is not alive.
sourcepub fn try_get_cloned<T>(self, entity: impl Entity) -> Result<T, EntityError>where
T: Clone + 'static,
pub fn try_get_cloned<T>(self, entity: impl Entity) -> Result<T, EntityError>where
T: Clone + 'static,
Queries components from specified entity.
Where query item is a reference to value the implements ToOwned.
Returns item converted to owned value.
This method locks only archetype to which entity belongs for the duration of the method itself.
sourcepub fn insert<T>(
self,
entity: impl Entity,
component: T,
) -> Result<(), NoSuchEntity>where
T: Component,
pub fn insert<T>(
self,
entity: impl Entity,
component: T,
) -> Result<(), NoSuchEntity>where
T: Component,
Attempts to inserts component to the specified entity.
If entity already had component of that type, old component value is replaced with new one. Otherwise new component is added to the entity.
If entity is not alive, fails with Err(NoSuchEntity).
§Example
let mut world = World::new();
let entity = world.spawn(()).id();
assert_eq!(world.try_has_component::<ExampleComponent>(entity), Ok(false));
world.insert(entity, ExampleComponent).unwrap();
assert_eq!(world.try_has_component::<ExampleComponent>(entity), Ok(true));sourcepub fn insert_external<T>(
self,
entity: impl Entity,
component: T,
) -> Result<(), NoSuchEntity>where
T: 'static,
pub fn insert_external<T>(
self,
entity: impl Entity,
component: T,
) -> Result<(), NoSuchEntity>where
T: 'static,
Attempts to inserts component to the specified entity.
If entity already had component of that type, old component value is replaced with new one. Otherwise new component is added to the entity.
If entity is not alive, fails with Err(NoSuchEntity).
§Example
let mut world = World::new();
let entity = world.spawn(()).id();
assert_eq!(world.try_has_component::<u32>(entity), Ok(false));
world.ensure_external_registered::<u32>();
world.insert_external(entity, 42u32).unwrap();
assert_eq!(world.try_has_component::<u32>(entity), Ok(true));sourcepub fn with<T>(
self,
entity: impl Entity,
f: impl FnOnce() -> T,
) -> Result<(), NoSuchEntity>where
T: Component,
pub fn with<T>(
self,
entity: impl Entity,
f: impl FnOnce() -> T,
) -> Result<(), NoSuchEntity>where
T: Component,
Attempts to inserts component to the specified entity.
If entity already had component of that type, old component value is preserved. Otherwise new component is added to the entity.
If entity is not alive, fails with Err(NoSuchEntity).
§Example
let mut world = World::new();
let entity = world.spawn(()).id();
assert_eq!(world.try_has_component::<ExampleComponent>(entity), Ok(false));
world.with(entity, || ExampleComponent).unwrap();
assert_eq!(world.try_has_component::<ExampleComponent>(entity), Ok(true));sourcepub fn with_external<T>(
self,
entity: impl Entity,
f: impl FnOnce() -> T,
) -> Result<(), NoSuchEntity>where
T: 'static,
pub fn with_external<T>(
self,
entity: impl Entity,
f: impl FnOnce() -> T,
) -> Result<(), NoSuchEntity>where
T: 'static,
Attempts to inserts component to the specified entity.
If entity already had component of that type, old component value is preserved. Otherwise new component is added to the entity.
If entity is not alive, fails with Err(NoSuchEntity).
§Example
let mut world = World::new();
let entity = world.spawn(()).id();
assert_eq!(world.try_has_component::<u32>(entity), Ok(false));
world.ensure_external_registered::<u32>();
world.with_external(entity, || 42u32).unwrap();
assert_eq!(world.try_has_component::<u32>(entity), Ok(true));sourcepub fn insert_bundle<B>(
self,
entity: impl Entity,
bundle: B,
) -> Result<(), NoSuchEntity>where
B: DynamicComponentBundle,
pub fn insert_bundle<B>(
self,
entity: impl Entity,
bundle: B,
) -> Result<(), NoSuchEntity>where
B: DynamicComponentBundle,
Inserts bundle of components to the specified entity.
This is moral equivalent to calling World::insert with each component separately,
but more efficient.
For each component type in bundle: If entity already had component of that type, old component value is replaced with new one. Otherwise new component is added to the entity.
If entity is not alive, fails with Err(NoSuchEntity).
§Example
let mut world = World::new();
let entity = world.spawn(()).id();
assert_eq!(world.try_has_component::<ExampleComponent>(entity), Ok(false));
world.insert_bundle(entity, (ExampleComponent,));
assert_eq!(world.try_has_component::<ExampleComponent>(entity), Ok(true));sourcepub fn insert_external_bundle<B>(
self,
entity: impl Entity,
bundle: B,
) -> Result<(), NoSuchEntity>where
B: DynamicBundle,
pub fn insert_external_bundle<B>(
self,
entity: impl Entity,
bundle: B,
) -> Result<(), NoSuchEntity>where
B: DynamicBundle,
Inserts bundle of components to the specified entity.
This is moral equivalent to calling World::insert with each component separately,
but more efficient.
If entity has component of any type in bundle already, it is replaced with new one. Otherwise components is added to the entity.
If entity is not alive, fails with Err(NoSuchEntity).
§Example
let mut world = World::new();
let entity = world.spawn(()).id();
assert_eq!(world.try_has_component::<ExampleComponent>(entity), Ok(false));
assert_eq!(world.try_has_component::<u32>(entity), Ok(false));
world.ensure_component_registered::<ExampleComponent>();
world.ensure_external_registered::<u32>();
world.insert_external_bundle(entity, (ExampleComponent, 42u32));
assert_eq!(world.try_has_component::<ExampleComponent>(entity), Ok(true));
assert_eq!(world.try_has_component::<u32>(entity), Ok(true));sourcepub fn with_bundle<B>(
self,
entity: impl Entity,
bundle: B,
) -> Result<(), NoSuchEntity>where
B: DynamicComponentBundle,
pub fn with_bundle<B>(
self,
entity: impl Entity,
bundle: B,
) -> Result<(), NoSuchEntity>where
B: DynamicComponentBundle,
Inserts bundle of components to the specified entity.
Adds only components missing from the entity.
Components that are already present are not replaced,
if replacing is required use FlowWorld::insert_bundle.
This function guarantees that no hooks are triggered, and entity cannot be despawned as a result of this operation.
If entity is not alive, fails with Err(NoSuchEntity).
§Example
let mut world = World::new();
let entity = world.spawn(()).id();
assert_eq!(world.try_has_component::<ExampleComponent>(entity), Ok(false));
world.insert_bundle(entity, (ExampleComponent,));
assert_eq!(world.try_has_component::<ExampleComponent>(entity), Ok(true));sourcepub fn with_external_bundle<B>(
self,
entity: impl Entity,
bundle: B,
) -> Result<(), NoSuchEntity>where
B: DynamicBundle,
pub fn with_external_bundle<B>(
self,
entity: impl Entity,
bundle: B,
) -> Result<(), NoSuchEntity>where
B: DynamicBundle,
Inserts bundle of components to the specified entity.
Adds only components missing from the entity.
Components that are already present are not replaced,
if replacing is required use FlowWorld::insert_bundle.
If entity is not alive, fails with Err(NoSuchEntity).
§Example
let mut world = World::new();
let entity = world.spawn(()).id();
assert_eq!(world.try_has_component::<ExampleComponent>(entity), Ok(false));
assert_eq!(world.try_has_component::<u32>(entity), Ok(false));
world.ensure_component_registered::<ExampleComponent>();
world.ensure_external_registered::<u32>();
world.insert_external_bundle(entity, (ExampleComponent, 42u32));
assert_eq!(world.try_has_component::<ExampleComponent>(entity), Ok(true));
assert_eq!(world.try_has_component::<u32>(entity), Ok(true));sourcepub fn remove<T>(self, entity: impl Entity) -> Result<Option<T>, NoSuchEntity>where
T: 'static,
pub fn remove<T>(self, entity: impl Entity) -> Result<Option<T>, NoSuchEntity>where
T: 'static,
Removes component from the specified entity and returns its value.
Returns Ok(Some(comp)) if component was removed.
Returns Ok(None) if entity does not have component of this type.
Returns Err(NoSuchEntity) if entity is not alive.
sourcepub fn drop<T>(self, entity: impl Entity) -> Result<(), NoSuchEntity>where
T: 'static,
pub fn drop<T>(self, entity: impl Entity) -> Result<(), NoSuchEntity>where
T: 'static,
Drops component from the specified entity.
Returns Err(NoSuchEntity) if entity is not alive.
sourcepub fn drop_erased(
self,
entity: impl Entity,
ty: TypeId,
) -> Result<(), NoSuchEntity>
pub fn drop_erased( self, entity: impl Entity, ty: TypeId, ) -> Result<(), NoSuchEntity>
Drops component from the specified entity.
Returns Err(NoSuchEntity) if entity is not alive.
sourcepub fn drop_bundle<B>(self, entity: impl Entity) -> Result<(), NoSuchEntity>where
B: Bundle,
pub fn drop_bundle<B>(self, entity: impl Entity) -> Result<(), NoSuchEntity>where
B: Bundle,
Drops entity’s components that are found in the specified bundle.
If entity is not alive, fails with Err(NoSuchEntity).
Unlike other methods that use Bundle trait, this method does not require
all components from bundle to be registered in the world.
Entity can’t have components that are not registered in the world,
so no need to drop them.
For this reason there’s no separate method that uses ComponentBundle trait.
§Example
struct OtherComponent;
let mut world = World::new();
let mut entity = world.spawn((ExampleComponent,)).id();
assert!(world.try_has_component::<ExampleComponent>(entity).unwrap());
world.drop_bundle::<(ExampleComponent, OtherComponent)>(entity).unwrap();
assert!(!world.try_has_component::<ExampleComponent>(entity).unwrap());sourcepub fn add_relation<R>(
self,
origin: impl Entity,
relation: R,
target: impl Entity,
) -> Result<(), NoSuchEntity>where
R: Relation,
pub fn add_relation<R>(
self,
origin: impl Entity,
relation: R,
target: impl Entity,
) -> Result<(), NoSuchEntity>where
R: Relation,
Adds relation between two entities to the FlowWorld.
If either entity is not alive, fails with Err(NoSuchEntity).
When either entity is despawned, relation is removed automatically.
Relations can be queried and filtered using queries from edict::relation module.
Relation must implement Relation trait that defines its behavior.
If relation already exists, then instance is replaced. If relation is symmetric then it is added in both directions. If relation is exclusive, then previous relation on origin is replaced, otherwise relation is added. If relation is exclusive and symmetric, then previous relation on target is replaced, otherwise relation is added.
sourcepub fn remove_relation<R>(
self,
origin: impl Entity,
target: impl Entity,
) -> Result<Option<R>, NoSuchEntity>where
R: Relation,
pub fn remove_relation<R>(
self,
origin: impl Entity,
target: impl Entity,
) -> Result<Option<R>, NoSuchEntity>where
R: Relation,
Removes relation between two entities in the FlowWorld.
If either entity is not alive, fails with Err(NoSuchEntity).
If relation does not exist, removes None.
When relation is removed, Relation::on_drop behavior is not executed.
For symmetric relations Relation::on_target_drop is also not executed.
sourcepub fn drop_relation<R>(
self,
origin: impl Entity,
target: impl Entity,
) -> Result<(), NoSuchEntity>where
R: Relation,
pub fn drop_relation<R>(
self,
origin: impl Entity,
target: impl Entity,
) -> Result<(), NoSuchEntity>where
R: Relation,
Drops relation between two entities in the FlowWorld.
If either entity is not alive, fails with Err(NoSuchEntity).
If relation does not exist, does nothing.
When relation is dropped, Relation::on_drop behavior is executed.
sourcepub fn insert_resource<T: 'static>(self, resource: T)
pub fn insert_resource<T: 'static>(self, resource: T)
Inserts resource instance. Old value is replaced.
To access resource, use FlowWorld::get_resource and FlowWorld::get_resource_mut methods.
§Examples
let mut world = World::new();
world.insert_resource(42i32);
assert_eq!(*world.get_resource::<i32>().unwrap(), 42);
*world.get_resource_mut::<i32>().unwrap() = 11;
assert_eq!(*world.get_resource::<i32>().unwrap(), 11);sourcepub fn with_resource<T: 'static>(self, f: impl FnOnce() -> T)
pub fn with_resource<T: 'static>(self, f: impl FnOnce() -> T)
Returns reference to the resource instance. Inserts new instance if it does not exist.
§Examples
let mut world = World::new();
let value = world.with_resource(|| 42i32);
assert_eq!(*value, 42);
*value = 11;
assert_eq!(*world.get_resource::<i32>().unwrap(), 11);sourcepub fn with_default_resource<T: Default + 'static>(self)
pub fn with_default_resource<T: Default + 'static>(self)
Returns reference to the resource instance. Inserts new instance if it does not exist.
§Examples
let mut world = World::new();
let value = world.with_default_resource::<u32>();
assert_eq!(*value, 0);
*value = 11;
assert_eq!(*world.get_resource::<u32>().unwrap(), 11);sourcepub fn remove_resource<T: 'static>(self) -> Option<T>
pub fn remove_resource<T: 'static>(self) -> Option<T>
Remove resource instance.
Returns None if resource was not found.
§Examples
let mut world = World::new();
world.insert_resource(42i32);
assert_eq!(*world.get_resource::<i32>().unwrap(), 42);
world.remove_resource::<i32>();
assert!(world.get_resource::<i32>().is_none());sourcepub fn copy_resource<T: Copy + 'static>(self) -> T
pub fn copy_resource<T: Copy + 'static>(self) -> T
sourcepub fn clone_resource<T: Clone + 'static>(self) -> T
pub fn clone_resource<T: Clone + 'static>(self) -> T
sourcepub fn spawn_empty(self) -> FlowEntity
pub fn spawn_empty(self) -> FlowEntity
Spawns a new entity in this world without components.
Returns FlowEntity for the newly spawned entity.
Entity will be alive until FlowWorld::despawn is called with EntityId of the spawned entity,
or despawn command recorded and executed by the FlowWorld.
§Panics
If new id cannot be allocated.
If too many entities are spawned.
Currently limit is set to u32::MAX entities per archetype and usize::MAX overall.
§Example
let mut world = World::new();
let mut entity = world.spawn_empty();
assert!(!entity.has_component::<ExampleComponent>());sourcepub fn spawn_one<T>(self, component: T) -> FlowEntitywhere
T: Component,
pub fn spawn_one<T>(self, component: T) -> FlowEntitywhere
T: Component,
Spawns a new entity in this world with provided component.
Returns FlowEntity for the newly spawned entity.
Entity will be alive until FlowWorld::despawn is called with EntityId of the spawned entity,
or despawn command recorded and executed by the FlowWorld.
§Panics
If new id cannot be allocated.
If too many entities are spawned.
Currently limit is set to u32::MAX entities per archetype and usize::MAX overall.
§Example
let mut world = World::new();
let mut entity = world.spawn_one(ExampleComponent);
assert!(entity.has_component::<ExampleComponent>());
let ExampleComponent = entity.remove().unwrap();
assert!(!entity.has_component::<ExampleComponent>());sourcepub fn spawn_one_external<T>(self, component: T) -> FlowEntitywhere
T: 'static,
pub fn spawn_one_external<T>(self, component: T) -> FlowEntitywhere
T: 'static,
Spawns a new entity in this world with provided component.
Returns FlowEntity for the newly spawned entity.
Entity will be alive until FlowWorld::despawn is called with EntityId of the spawned entity,
or despawn command recorded and executed by the FlowWorld.
Component must be previously registered.
If component implements Component it could be registered implicitly
on first call to FlowWorld::spawn, FlowWorld::spawn_one, FlowWorld::spawn_batch, FlowWorld::insert or FlowWorld::insert_bundle and their deferred versions.
Otherwise component must be pre-registered explicitly by WorldBuilder::register_component or later by FlowWorld::ensure_component_registered.
Non Component type must be pre-registered by WorldBuilder::register_external or later by FlowWorld::ensure_external_registered.
§Panics
If new id cannot be allocated.
If too many entities are spawned.
Currently limit is set to u32::MAX entities per archetype and usize::MAX overall.
§Example
let mut world = World::new();
world.ensure_external_registered::<u32>();
let mut entity = world.spawn_one_external(42u32);
assert!(entity.has_component::<u32>());sourcepub fn spawn<B>(self, bundle: B) -> FlowEntitywhere
B: DynamicComponentBundle,
pub fn spawn<B>(self, bundle: B) -> FlowEntitywhere
B: DynamicComponentBundle,
Spawns a new entity in this world with provided bundle of components.
Returns FlowEntity for the newly spawned entity.
Entity will be alive until FlowWorld::despawn is called with EntityId of the spawned entity,
or despawn command recorded and executed by the FlowWorld.
§Panics
If new id cannot be allocated.
If too many entities are spawned.
Currently limit is set to u32::MAX entities per archetype and usize::MAX overall.
§Example
let mut world = World::new();
let mut entity = world.spawn((ExampleComponent,));
assert!(entity.has_component::<ExampleComponent>());
let ExampleComponent = entity.remove().unwrap();
assert!(!entity.has_component::<ExampleComponent>());sourcepub fn spawn_at<B>(self, id: EntityId, bundle: B) -> FlowEntitywhere
B: DynamicComponentBundle,
pub fn spawn_at<B>(self, id: EntityId, bundle: B) -> FlowEntitywhere
B: DynamicComponentBundle,
Spawns a new entity in this world with specific ID and bundle of components.
The World must be configured to never allocate this ID.
Spawned entity is populated with all components from the bundle.
Entity will be alive until FlowWorld::despawn is called with the same EntityId.
§Panics
Panics if the id is already used by the world.
§Example
let mut world = World::new();
let id = EntityId::from_bits(42).unwrap();
let mut entity = world.spawn_at(id, (ExampleComponent,));
assert!(entity.has_component::<ExampleComponent>());
let ExampleComponent = entity.remove().unwrap();
assert!(!entity.has_component::<ExampleComponent>());sourcepub fn spawn_or_insert<B>(self, id: EntityId, bundle: B) -> FlowEntitywhere
B: DynamicComponentBundle,
pub fn spawn_or_insert<B>(self, id: EntityId, bundle: B) -> FlowEntitywhere
B: DynamicComponentBundle,
Spawns a new entity in this world with specific ID and bundle of components.
The World must be configured to never allocate this ID.
Spawned entity is populated with all components from the bundle.
Entity will be alive until FlowWorld::despawn is called with the same EntityId.
§Panics
Panics if the id is already used by the world.
§Example
let mut world = World::new();
let id = EntityId::from_bits(42).unwrap();
let mut entity = world.spawn_or_insert(id, (ExampleComponent,));
assert!(entity.has_component::<ExampleComponent>());
let ExampleComponent = entity.remove().unwrap();
assert!(!entity.has_component::<ExampleComponent>());sourcepub fn spawn_external<B>(self, bundle: B) -> FlowEntitywhere
B: DynamicBundle,
pub fn spawn_external<B>(self, bundle: B) -> FlowEntitywhere
B: DynamicBundle,
Spawns a new entity in this world with provided bundle of components.
Returns FlowEntity handle to the newly spawned entity.
Spawned entity is populated with all components from the bundle.
Entity will be alive until despawned.
Components must be previously registered.
If component implements Component it could be registered implicitly
on first call to FlowWorld::spawn, FlowWorld::spawn_one, FlowWorld::spawn_batch, FlowWorld::insert or FlowWorld::insert_bundle and their deferred versions.
Otherwise component must be pre-registered explicitly by WorldBuilder::register_component or later by FlowWorld::ensure_component_registered.
Non Component type must be pre-registered by WorldBuilder::register_external or later by FlowWorld::ensure_external_registered.
§Panics
Panics if new id cannot be allocated.
§Example
let mut world = World::new();
world.ensure_external_registered::<u32>();
world.ensure_component_registered::<ExampleComponent>();
let mut entity = world.spawn_external((42u32, ExampleComponent));
assert!(entity.has_component::<u32>());
assert_eq!(entity.remove(), Some(42u32));
assert!(!entity.has_component::<u32>());sourcepub fn spawn_external_at<B>(self, id: EntityId, bundle: B) -> FlowEntitywhere
B: DynamicBundle,
pub fn spawn_external_at<B>(self, id: EntityId, bundle: B) -> FlowEntitywhere
B: DynamicBundle,
Spawns a new entity in this world with provided bundle of components. The id must be unused by the world. Spawned entity is populated with all components from the bundle. Entity will be alive until despawned.
Components must be previously registered.
If component implements Component it could be registered implicitly
on first call to FlowWorld::spawn, FlowWorld::spawn_one, FlowWorld::spawn_batch, FlowWorld::insert or FlowWorld::insert_bundle and their deferred versions.
Otherwise component must be pre-registered explicitly by WorldBuilder::register_component or later by FlowWorld::ensure_component_registered.
Non Component type must be pre-registered by WorldBuilder::register_external or later by FlowWorld::ensure_external_registered.
§Panics
Panics if the id is already used by the world.
§Example
let mut world = World::new();
world.ensure_external_registered::<u32>();
world.ensure_component_registered::<ExampleComponent>();
let mut entity = world.spawn_external((42u32, ExampleComponent));
assert!(entity.has_component::<u32>());
assert_eq!(entity.remove(), Some(42u32));
assert!(!entity.has_component::<u32>());sourcepub fn spawn_batch<B, I>(self, bundles: I) -> SpawnBatch<I::IntoIter> ⓘwhere
I: IntoIterator<Item = B>,
B: ComponentBundle,
pub fn spawn_batch<B, I>(self, bundles: I) -> SpawnBatch<I::IntoIter> ⓘwhere
I: IntoIterator<Item = B>,
B: ComponentBundle,
Returns an iterator which spawns and yield entities using bundles yielded from provided bundles iterator.
When bundles iterator returns None, returned iterator returns None too.
If bundles iterator is fused, returned iterator is fused too. If bundles iterator is double-ended, returned iterator is double-ended too. If bundles iterator has exact size, returned iterator has exact size too.
Skipping items on returned iterator will cause bundles iterator skip bundles and not spawn entities.
Returned iterator attempts to optimize storage allocation for entities
if consumed with functions like fold, rfold, for_each or collect.
When returned iterator is dropped, no more entities will be spawned even if bundles iterator has items left.
sourcepub fn spawn_batch_external<B, I>(self, bundles: I) -> SpawnBatch<I::IntoIter> ⓘwhere
I: IntoIterator<Item = B>,
B: Bundle,
pub fn spawn_batch_external<B, I>(self, bundles: I) -> SpawnBatch<I::IntoIter> ⓘwhere
I: IntoIterator<Item = B>,
B: Bundle,
Returns an iterator which spawns and yield entities using bundles yielded from provided bundles iterator.
When bundles iterator returns None, returned iterator returns None too.
If bundles iterator is fused, returned iterator is fused too. If bundles iterator is double-ended, returned iterator is double-ended too. If bundles iterator has exact size, returned iterator has exact size too.
Skipping items on returned iterator will cause bundles iterator skip bundles and not spawn entities.
Returned iterator attempts to optimize storage allocation for entities
if consumed with functions like fold, rfold, for_each or collect.
When returned iterator is dropped, no more entities will be spawned even if bundles iterator has items left.
Components must be previously registered.
If component implements Component it could be registered implicitly
on first call to FlowWorld::spawn, FlowWorld::spawn_one, FlowWorld::spawn_batch, FlowWorld::insert or FlowWorld::insert_bundle and their deferred versions.
Otherwise component must be pre-registered explicitly by WorldBuilder::register_component or later by FlowWorld::ensure_component_registered.
Non Component type must be pre-registered by WorldBuilder::register_external or later by FlowWorld::ensure_external_registered.
sourcepub fn despawn(self, entity: impl Entity) -> Result<(), NoSuchEntity>
pub fn despawn(self, entity: impl Entity) -> Result<(), NoSuchEntity>
Despawns an entity with specified id.
Returns [Err(NoSuchEntity)] if entity does not exists.
§Example
let mut world = World::new();
let entity = world.spawn((ExampleComponent,)).id();
assert!(world.despawn(entity).is_ok(), "Entity should be despawned by this call");
assert!(world.despawn(entity).is_err(), "Already despawned");sourcepub fn ensure_component_registered<T>(self)where
T: Component,
pub fn ensure_component_registered<T>(self)where
T: Component,
Explicitly registers component type.
Unlike WorldBuilder::register_component method, this method does not return reference to component configuration,
once FlowWorld is created overriding component behavior is not possible.
Component types are implicitly registered on first use by most methods.
This method is only needed if you want to use component type using
FlowWorld::insert_external, FlowWorld::insert_external_bundle or FlowWorld::spawn_external.
sourcepub fn ensure_external_registered<T>(&mut self)where
T: 'static,
pub fn ensure_external_registered<T>(&mut self)where
T: 'static,
Explicitly registers external type.
Unlike WorldBuilder::register_external method, this method does not return reference to component configuration,
once FlowWorld is created overriding component behavior is not possible.
External component types are not implicitly registered on first use.
This method is needed if you want to use component type with
FlowWorld::insert_external, FlowWorld::insert_external_bundle or FlowWorld::spawn_external.
sourcepub fn ensure_bundle_registered<B>(&mut self)where
B: ComponentBundle,
pub fn ensure_bundle_registered<B>(&mut self)where
B: ComponentBundle,
Explicitly registers bundle of component types.
This method is only needed if you want to use bundle of component types using
FlowWorld::insert_external_bundle or FlowWorld::spawn_external.
sourcepub fn assert_bundle_registered<B>(&self)where
B: Bundle,
pub fn assert_bundle_registered<B>(&self)where
B: Bundle,
Asserts that all components from the bundle are registered.
source§impl FlowWorld
impl FlowWorld
sourcepub fn spawn_flow<F>(self, flow: F)where
F: IntoFlow,
pub fn spawn_flow<F>(self, flow: F)where
F: IntoFlow,
Spawn a flow in the world.
It will be polled during Flows::execute until completion.
sourcepub fn spawn_flow_for<F>(&self, entity: EntityId, flow: F)where
F: IntoEntityFlow,
pub fn spawn_flow_for<F>(&self, entity: EntityId, flow: F)where
F: IntoEntityFlow,
Spawns a flow for an entity in the world.
It will be polled during Flows::execute until completion
or until the entity is despawned.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FlowWorld
impl RefUnwindSafe for FlowWorld
impl Send for FlowWorld
impl Sync for FlowWorld
impl Unpin for FlowWorld
impl UnwindSafe for FlowWorld
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)