Struct SharedWorld

Source
pub struct SharedWorld(/* private fields */);
Expand description

Helper type to share the world parameter passed to Dispatcher::dispatch.

Methods from Deref<Target = World>§

Source

pub fn resource<T: Resource>(&self) -> Ref<'_, T>

Source

pub fn resource_mut<T: Resource>(&self) -> RefMut<'_, T>

Source

pub fn resource_raw(&self, id: &ResourceId) -> Option<&Cell<Box<dyn Resource>>>

Source

pub fn entities(&self) -> Read<'_, Entities>

Source

pub fn entities_mut(&self) -> RefMut<'_, Entities>

Source

pub fn lazy(&self) -> Read<'_, Lazy>

Source

pub fn component<T: Component>(&self) -> ReadStorage<'_, T>

Source

pub fn component_mut<T: Component>(&self) -> WriteStorage<'_, T>

Source

pub fn is_alive(&self, entity: Entity) -> bool

Methods from Deref<Target = Resources>§

Source

pub fn entry<R>(&mut self) -> Entry<'_, R>
where R: Resource,

Returns an entry for the resource with type R.

Source

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));
Source

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).

Source

pub fn contains<R>(&self) -> bool
where R: Resource,

Returns true if the specified resource type R exists in self.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn get_raw(&self, id: &ResourceId) -> Option<&Cell<Box<dyn Resource>>>

Get raw access to the underlying cell.

Trait Implementations§

Source§

impl Clone for SharedWorld

Source§

fn clone(&self) -> SharedWorld

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for SharedWorld

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Deref for SharedWorld

Source§

type Target = World

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Send for SharedWorld

Source§

impl Sync for SharedWorld

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TryDefault for T
where T: Default,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Resource for T
where T: Any + Send + Sync,