Struct shred::Resources
[−]
[src]
pub struct Resources { /* fields omitted */ }
A resource container, which provides methods to access to the contained resources.
Methods
impl Resources
[src]
fn new() -> Self
Creates a new, empty resource container.
fn add<R, ID>(&mut self, r: R, id: ID) where
R: Resource,
ID: Hash + Eq,
R: Resource,
ID: Hash + Eq,
Adds a new resource to this container.
Panics
Panics if the resource is already registered.
Examples
To make a type a resource, simply
implement the [Resource
] trait:
use shred::Resource; struct MyRes(i32); impl Resource for MyRes {}
When you have a resource, simply register it like this:
use shred::Resources; let mut res = Resources::new(); res.add(MyRes(5), 0);
unsafe fn fetch<T, ID>(&self, id: ID) -> Fetch<T> where
T: Resource,
ID: Hash + Eq,
T: Resource,
ID: Hash + Eq,
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(TaskData)]
passes ()
as id.
Safety
This method is marked as unsafe
as calling
it means you are sure about the implied borrowing
rules.
Panics
Panics if the resource is being accessed mutably. Also panics if there is no such resource.
unsafe fn fetch_mut<T, ID>(&self, id: ID) -> FetchMut<T> where
T: Resource,
ID: Hash + Eq,
T: Resource,
ID: Hash + Eq,
Fetches the resource with the specified type T
mutably.
Please see fetch
for details.
unsafe fn fetch_id<ID>(&self, id: TypeId, comp_id: ID) -> FetchId where
ID: Hash + Eq,
ID: Hash + Eq,
Fetches the resource with the specified type id.
Please see fetch
for details.
unsafe fn fetch_id_mut<ID>(&self, id: TypeId, comp_id: ID) -> FetchIdMut where
ID: Hash + Eq,
ID: Hash + Eq,
Fetches the resource with the specified type id mutably.
Please see fetch
for details.