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 ResourceId
s, which consist of a TypeId
.
Implementations
sourceimpl Resources
impl Resources
sourcepub fn insert<R>(&mut self, r: R)where
R: Resource,
pub fn insert<R>(&mut self, r: R)where
R: Resource,
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));
sourcepub fn has_value<R>(&self) -> boolwhere
R: Resource,
pub fn has_value<R>(&self) -> boolwhere
R: Resource,
Returns true if the specified resource type R
exists in self
.
sourcepub fn has_value_raw(&self, id: ResourceId) -> bool
pub fn has_value_raw(&self, id: ResourceId) -> bool
Returns true if the specified resource type exists in self
.
sourcepub fn entry<R>(&mut self) -> Entry<'_, R>where
R: Resource,
pub fn entry<R>(&mut self) -> Entry<'_, R>where
R: Resource,
Returns an entry for the resource with type R
.
sourcepub fn fetch<T>(&self) -> Fetch<'_, T>where
T: Resource,
pub fn fetch<T>(&self) -> Fetch<'_, T>where
T: Resource,
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.
sourcepub fn try_fetch<T>(&self) -> Option<Fetch<'_, T>>where
T: Resource,
pub fn try_fetch<T>(&self) -> Option<Fetch<'_, T>>where
T: Resource,
Like fetch
, but returns an Option
instead of inserting a default value
in case the resource does not exist.
sourcepub fn fetch_mut<T>(&self) -> FetchMut<'_, T>where
T: Resource,
pub fn fetch_mut<T>(&self) -> FetchMut<'_, T>where
T: Resource,
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.
sourcepub fn try_fetch_mut<T>(&self) -> Option<FetchMut<'_, T>>where
T: Resource,
pub fn try_fetch_mut<T>(&self) -> Option<FetchMut<'_, T>>where
T: Resource,
Like fetch_mut
, but returns an Option
instead of inserting a default value
in case the resource does not exist.
sourcepub fn try_fetch_internal(
&self,
id: TypeId
) -> Option<&TrustCell<Box<dyn Resource + 'static, Global>>>
pub fn try_fetch_internal(
&self,
id: TypeId
) -> Option<&TrustCell<Box<dyn Resource + 'static, Global>>>
Internal function for fetching resources, should only be used if you know what you’re doing.
sourcepub fn get_mut<T>(&mut self) -> Option<&mut T>where
T: Resource,
pub fn get_mut<T>(&mut self) -> Option<&mut T>where
T: Resource,
Retrieves a resource without fetching, which is cheaper, but only available with
&mut self
.
sourcepub fn get_mut_raw(
&mut self,
id: TypeId
) -> Option<&mut (dyn Resource + 'static)>
pub fn get_mut_raw(
&mut self,
id: TypeId
) -> Option<&mut (dyn Resource + 'static)>
Retrieves a resource without fetching, which is cheaper, but only available with
&mut self
.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Resources
impl Send for Resources
impl Sync for Resources
impl Unpin for Resources
impl !UnwindSafe for Resources
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> TryDefault for Twhere
T: Default,
impl<T> TryDefault for Twhere
T: Default,
sourcefn try_default() -> Result<T, String>
fn try_default() -> Result<T, String>
sourcefn unwrap_default() -> Self
fn unwrap_default() -> Self
try_default
and panics on an error case.