pub struct Resources(_);
Expand description

A type map for holding resources.

Resources replace global variables and my be accessed by systems that know their type.

Examples

struct WrapperType(u32);

let mut resources = Resources::new();

// Insert multiple resources
resources.insert(42_u32);
resources.insert(WrapperType(23));

// Borrow a resource immutably
let wrapped_res = resources.get::<WrapperType>();

// Borrow a resource mutably
let mut u32_res = resources.get_mut::<u32>();
*u32_res += 1;

Implementations

Create an empty resources map.

Insert a resource.

Panics

Panics if a resource of the same type is already present.

Drop all resources.

Borrow a resource immutably

Panics

Panics if the resource is not present.

Borrow a resource mutably

Panics

Panics if the resource is not present.

Trait Implementations

Create an empty resources map.

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

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.