Struct resman::Resources [−][src]
pub struct Resources(_);
Expand description
Map from TypeId
to type.
Implementations
A Resource container, which provides methods to insert, access and manage the contained resources.
Many methods take &self
which works because everything
is stored with interior mutability. In case you violate
the borrowing rules of Rust (multiple reads xor one write),
you will get a panic.
Resource Ids
Resources are identified by TypeId
s, which consist of a TypeId
.
Creates an empty Resources
map.
The map is initially created with a capacity of 0, so it will not allocate until it is first inserted into.
Examples
use resman::Resources; let mut resources = Resources::new();
Creates an empty Resources
map with the specified capacity.
The map will be able to hold at least capacity elements without reallocating. If capacity is 0, the map will not allocate.
Examples
use resman::Resources; let resources: Resources = Resources::with_capacity(10);
Returns the number of elements the map can hold without reallocating.
This number is a lower bound; the Resources<K, V>
might be able to
hold more, but is guaranteed to be able to hold at least this many.
Examples
use resman::Resources; let resources: Resources = Resources::with_capacity(100); assert!(resources.capacity() >= 100);
Returns an entry for the resource with type R
.
Inserts a resource into this container. If the resource existed before, it will be overwritten.
Examples
Every type satisfying Any + Send + Sync
automatically
implements Resource
, thus can be added:
struct MyRes(i32);
When you have a resource, simply insert it like this:
use resman::Resources; let mut resources = Resources::default(); resources.insert(MyRes(5));
Removes a resource of type R
from this container and returns its
ownership to the caller. In case there is no such resource in this,
container, None
will be returned.
Use this method with caution; other functions and systems might assume this resource still exists. Thus, only use this if you’re sure no system will try to access this resource after you removed it (or else you will get a panic).
Returns true if the specified resource type R
exists in self
.
Returns the R
resource in the resource map.
See try_borrow
for a non-panicking version of this function.
Panics
Panics if the resource doesn’t exist. Panics if the resource is being accessed mutably.
Returns an immutable reference to R
if it exists, None
otherwise.
Returns a mutable reference to R
if it exists, None
otherwise.
Panics
Panics if the resource doesn’t exist. Panics if the resource is already accessed.
Returns a mutable reference to R
if it exists, None
otherwise.
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
Auto Trait Implementations
impl !RefUnwindSafe for Resources
impl !UnwindSafe for Resources
Blanket Implementations
Mutably borrows from an owned value. Read more
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more