Struct specs::Resources

source ·
pub struct Resources { /* private fields */ }
Expand description

A resource container, which provides methods to access to the contained resources.

Resource Ids

Resources are identified by ResourceIds, which consist of a TypeId.

Implementations

Creates a new, empty resource container.

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::Resources;

let mut res = Resources::new();
res.insert(MyRes(5));

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

Returns true if the specified resource type exists in self.

Returns an entry for the resource with type R.

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.

Like fetch, but returns an Option instead of inserting a default value in case the resource does not exist.

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.

Like fetch_mut, but returns an Option instead of inserting a default value in case the resource does not exist.

Internal function for fetching resources, should only be used if you know what you’re doing.

Retrieves a resource without fetching, which is cheaper, but only available with &mut self.

Retrieves a resource without fetching, which is cheaper, but only available with &mut self.

Trait Implementations

Immutably borrows from an owned value. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Tries to create the default.
Calls try_default and panics on an error case.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.