pub struct LocalResourceStorage { /* private fields */ }Expand description
Storage for various resources identified by their TypeId.
Implementations§
Source§impl LocalResourceStorage
impl LocalResourceStorage
pub fn new() -> Self
Sourcepub fn insert<R: LocalResource>(&mut self, resource: R)
pub fn insert<R: LocalResource>(&mut self, resource: R)
Inserts a new resource into the storage.
If a resource of the same type already exists, it will be replaced.
Sourcepub fn fetch<R: LocalResource>(&self) -> &R
pub fn fetch<R: LocalResource>(&self) -> &R
Sourcepub fn fetch_mut<R: LocalResource>(&mut self) -> &mut R
pub fn fetch_mut<R: LocalResource>(&mut self) -> &mut R
Retrieves a mutable reference to a resource of type R.
§Panics
Panics if the resource does not exist.
Sourcepub fn get<R: LocalResource + 'static>(&self) -> Option<&R>
pub fn get<R: LocalResource + 'static>(&self) -> Option<&R>
Retrieves an immutable reference to a resource of type R.
Returns Some(&R) if the resource exists, otherwise returns None.
Sourcepub fn get_mut<R: LocalResource + 'static>(&mut self) -> Option<&mut R>
pub fn get_mut<R: LocalResource + 'static>(&mut self) -> Option<&mut R>
Retrieves a mutable reference to a resource of type R.
Returns Some(&mut R) if the resource exists, otherwise returns None.
Sourcepub fn remove<R: LocalResource>(&mut self) -> Option<R>
pub fn remove<R: LocalResource>(&mut self) -> Option<R>
Removes a resource of type R from the storage.
Returns Some(R) if the resource was present, otherwise None.
§Panics
Panics if the resource stored is not of the expected type R. Should be very unlikely.
Sourcepub fn contains<R: LocalResource>(&self) -> bool
pub fn contains<R: LocalResource>(&self) -> bool
Checks if a resource of type R exists in the storage.
Trait Implementations§
Source§impl Debug for LocalResourceStorage
impl Debug for LocalResourceStorage
Auto Trait Implementations§
impl Freeze for LocalResourceStorage
impl !RefUnwindSafe for LocalResourceStorage
impl !Send for LocalResourceStorage
impl !Sync for LocalResourceStorage
impl Unpin for LocalResourceStorage
impl !UnwindSafe for LocalResourceStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more