[−][src]Struct shred::World
A resource container, which provides methods to access to the contained resources.
Resource Ids
Resources are identified by ResourceId
s, which consist of a TypeId
.
Methods
impl World
[src]
pub fn empty() -> Self
[src]
Creates a new, empty resource container.
Note that if you're using Specs, you should use WorldExt::new
instead.
pub fn insert<R>(&mut self, r: R) where
R: Resource,
[src]
R: Resource,
Inserts a resource into this container. If the resource existed before, it will be overwritten.
Examples
Every type satisfying Any + Debug + Send + Sync
automatically
implements Resource
, thus can be added:
#[derive(Debug)] struct MyRes(i32);
When you have a resource, simply insert it like this:
use shred::World; let mut world = World::empty(); world.insert(MyRes(5));
pub fn remove<R>(&mut self) -> Option<R> where
R: Resource,
[src]
R: Resource,
Removes a resource of type R
from the World
and returns its
ownership to the caller. In case there is no such resource in this
World
, 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).
pub fn has_value<R>(&self) -> bool where
R: Resource,
[src]
R: Resource,
Returns true if the specified resource type R
exists in self
.
pub fn has_value_raw(&self, id: ResourceId) -> bool
[src]
Returns true if the specified resource type exists in self
.
pub fn entry<R>(&mut self) -> Entry<R> where
R: Resource,
[src]
R: Resource,
Returns an entry for the resource with type R
.
pub fn fetch<T>(&self) -> Fetch<T> where
T: Resource,
[src]
T: 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.
pub fn try_fetch<T>(&self) -> Option<Fetch<T>> where
T: Resource,
[src]
T: Resource,
Like fetch
, but returns an Option
instead of inserting a default
value in case the resource does not exist.
pub fn try_fetch_by_id<T>(&self, id: ResourceId) -> Option<Fetch<T>> where
T: Resource,
[src]
T: Resource,
Like try_fetch
, but fetches the resource by its ResourceId
which
allows using a dynamic ID.
This is usually not what you need; please read the type-level
documentation of ResourceId
.
Panics
This method panics if id
refers to a different type ID than T
.
pub fn fetch_mut<T>(&self) -> FetchMut<T> where
T: Resource,
[src]
T: 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.
pub fn try_fetch_mut<T>(&self) -> Option<FetchMut<T>> where
T: Resource,
[src]
T: Resource,
Like fetch_mut
, but returns an Option
instead of inserting a default
value in case the resource does not exist.
pub fn try_fetch_mut_by_id<T>(&self, id: ResourceId) -> Option<FetchMut<T>> where
T: Resource,
[src]
T: Resource,
Like try_fetch_mut
, but fetches the resource by its ResourceId
which
allows using a dynamic ID.
This is usually not what you need; please read the type-level
documentation of ResourceId
.
Panics
This method panics if id
refers to a different type ID than T
.
pub fn insert_by_id<R>(&mut self, id: ResourceId, r: R) where
R: Resource,
[src]
R: Resource,
Internal function for inserting resources, should only be used if you know what you're doing.
This is useful for inserting resources with a custom ResourceId
.
Panics
This method panics if id
refers to a different type ID than R
.
pub fn remove_by_id<R>(&mut self, id: ResourceId) -> Option<R> where
R: Resource,
[src]
R: Resource,
Internal function for removing resources, should only be used if you know what you're doing.
This is useful for removing resources with a custom ResourceId
.
Panics
This method panics if id
refers to a different type ID than R
.
pub fn try_fetch_internal(
&self,
id: ResourceId
) -> Option<&TrustCell<Box<dyn Resource>>>
[src]
&self,
id: ResourceId
) -> Option<&TrustCell<Box<dyn Resource>>>
Internal function for fetching resources, should only be used if you know what you're doing.
pub fn get_mut<T: Resource>(&mut self) -> Option<&mut T>
[src]
Retrieves a resource without fetching, which is cheaper, but only
available with &mut self
.
pub fn get_mut_raw(&mut self, id: ResourceId) -> Option<&mut dyn Resource>
[src]
Retrieves a resource without fetching, which is cheaper, but only
available with &mut self
.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: Any,
[src]
T: Any,