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
and a usize. The usize may be used as
an additional identifier. In many cases, there
are convenience methods which assume this id is 0.
Methods
impl Resources[src]
fn new() -> Self[src]
Creates a new, empty resource container.
fn add<R>(&mut self, r: R) where
R: Resource, [src]
R: Resource,
Adds a new resource to this container.
This method calls add_with_id with
0 for the id.
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));
fn add_with_id<R>(&mut self, r: R, id: usize) where
R: Resource, [src]
R: Resource,
Like add(), but allows specifying
and id while add() assumes 0.
fn has_value(&self, res_id: ResourceId) -> bool[src]
Returns true if the specified type / id combination is registered.
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.
fn fetch<T>(&self, id: usize) -> 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.
fn try_fetch<T>(&self, id: usize) -> 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.
fn fetch_mut<T>(&self, id: usize) -> FetchMut<T> where
T: Resource, [src]
T: Resource,
Fetches the resource with the specified type T mutably.
Please see fetch for details.
fn try_fetch_mut<T>(&self, id: usize) -> 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.
fn fetch_id(&self, id: TypeId, comp_id: usize) -> FetchId[src]
Fetches the resource with the specified type id.
Please see fetch for details.
Panics
Panics if no resource with the id exists.
fn try_fetch_id(&self, id: TypeId, comp_id: usize) -> Option<FetchId>[src]
Like fetch_id, but returns an Option rather than panicking.
fn fetch_id_mut(&self, id: TypeId, comp_id: usize) -> FetchIdMut[src]
Fetches the resource with the specified type id mutably.
Please see fetch for details.
Panics
Panics if no resource with the id exists.
fn try_fetch_id_mut(&self, id: TypeId, comp_id: usize) -> Option<FetchIdMut>[src]
Like fetch_id_mut, but returns an Option rather than panicking.