pub struct World(/* private fields */);
Implementations§
Source§impl World
impl World
pub fn register_component<T: Component>(&mut self)
pub fn register_component_with_storage<T, F>(&mut self, storage: F)
pub fn register_resource<T: Resource>(&mut self, res: T)
pub fn resource<T: Resource>(&self) -> Ref<'_, T>
pub fn resource_mut<T: Resource>(&self) -> RefMut<'_, T>
pub fn resource_raw(&self, id: &ResourceId) -> Option<&Cell<Box<dyn Resource>>>
pub fn entities(&self) -> Read<'_, Entities>
pub fn entities_mut(&self) -> RefMut<'_, Entities>
pub fn lazy(&self) -> Read<'_, Lazy>
pub fn component<T: Component>(&self) -> ReadStorage<'_, T>
pub fn component_mut<T: Component>(&self) -> WriteStorage<'_, T>
pub fn create_entity(&mut self) -> EntityBuilder<'_>
pub fn is_alive(&self, entity: Entity) -> bool
pub async fn maintain(&mut self)
Methods from Deref<Target = Resources>§
Sourcepub fn entry<R>(&mut self) -> Entry<'_, R>where
R: Resource,
pub fn entry<R>(&mut self) -> Entry<'_, R>where
R: Resource,
Returns an entry for the resource with type R
.
Sourcepub fn insert<R>(&mut self, r: R)where
R: Resource,
pub fn insert<R>(&mut self, r: R)where
R: Resource,
Inserts a resource into this container. If the resource existed before, it will be overwritten.
§Examples
Every type satisfying Any + Send + Sync
automatically
implements Resource
, thus can be added:
struct MyRes(i32);
When you have a resource, simply insert it like this:
use async_ecs::World;
let mut world = World::default();
world.insert(MyRes(5));
Sourcepub fn remove<R>(&mut self) -> Option<R>where
R: Resource,
pub fn remove<R>(&mut self) -> Option<R>where
R: Resource,
Removes a resource of type R
from this container and returns its
ownership to the caller. In case there is no such resource in this,
container, None
will be returned.
Use this method with caution; other functions and systems might assume this resource still exists. Thus, only use this if you’re sure no system will try to access this resource after you removed it (or else you will get a panic).
Sourcepub fn contains<R>(&self) -> boolwhere
R: Resource,
pub fn contains<R>(&self) -> boolwhere
R: Resource,
Returns true if the specified resource type R
exists in self
.
Sourcepub fn borrow<R>(&self) -> Ref<'_, R>where
R: Resource,
pub fn borrow<R>(&self) -> Ref<'_, R>where
R: Resource,
Fetches the resource with the specified type T
or panics if it doesn’t
exist.
§Panics
Panics if the resource doesn’t exist. Panics if the resource is being accessed mutably.
Sourcepub fn try_borrow<R>(&self) -> Option<Ref<'_, R>>where
R: Resource,
pub fn try_borrow<R>(&self) -> Option<Ref<'_, R>>where
R: Resource,
Like fetch
, but returns an Option
instead of inserting a default
value in case the resource does not exist.
Sourcepub fn borrow_mut<R>(&self) -> RefMut<'_, R>where
R: Resource,
pub fn borrow_mut<R>(&self) -> RefMut<'_, R>where
R: Resource,
Fetches the resource with the specified type T
mutably.
Please see fetch
for details.
§Panics
Panics if the resource doesn’t exist. Panics if the resource is already being accessed.
Sourcepub fn try_borrow_mut<R>(&self) -> Option<RefMut<'_, R>>where
R: Resource,
pub fn try_borrow_mut<R>(&self) -> Option<RefMut<'_, R>>where
R: Resource,
Like fetch_mut
, but returns an Option
instead of inserting a default
value in case the resource does not exist.
Sourcepub fn get_mut<R: Resource>(&mut self) -> Option<&mut R>
pub fn get_mut<R: Resource>(&mut self) -> Option<&mut R>
Retrieves a resource without fetching, which is cheaper, but only
available with &mut self
.
Sourcepub fn get_resource_mut(&mut self, id: ResourceId) -> Option<&mut dyn Resource>
pub fn get_resource_mut(&mut self, id: ResourceId) -> Option<&mut dyn Resource>
Retrieves a resource without fetching, which is cheaper, but only
available with &mut self
.