Struct shred::Resources
[−]
[src]
pub struct Resources { /* fields omitted */ }
A resource container, which provides methods to access to the contained resources.
Resource Ids
Resources are in general identified
by ResourceId
, which consists of a TypeId
.
Methods
impl Resources
[src]
pub fn new() -> Self
[src]
Creates a new, empty resource container.
pub fn add<R>(&mut self, r: R) where
R: Resource,
[src]
R: Resource,
Adds a new resource to this container.
Panics
Panics if the resource is already registered.
Examples
Every type satisfying Any + Debug + Send + Sync
automatically implements Resource
:
#[derive(Debug)] struct MyRes(i32);
When you have a resource, simply register it like this:
use shred::Resources; let mut res = Resources::new(); res.add(MyRes(5));
pub fn has_value(&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
and id 0.
pub fn fetch<T>(&self) -> Fetch<T> where
T: Resource,
[src]
T: Resource,
Fetches the resource with the specified type T
.
The id is useful if you don't define your resources
in Rust or you want a more dynamic resource handling.
By default, the #[derive(SystemData)]
passes ()
as id.
Panics
Panics if the resource is being accessed mutably. Also panics if there is no such resource.
pub fn try_fetch<T>(&self) -> Option<Fetch<T>> where
T: Resource,
[src]
T: Resource,
Like fetch
, but returns an Option
instead of panicking in the case of the resource
being accessed mutably.
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.
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 panicking in the case of the resource
being accessed mutably.