pub struct Resources { /* private fields */ }Expand description
Container for singleton resources stored inside the ECS world.
All resources live on a single hidden entity so they participate in the
same borrow-checking rules as regular components. Resources is passed
to every system alongside the hecs::World.
Implementations§
Source§impl Resources
impl Resources
Sourcepub fn new(world: &mut World) -> Self
pub fn new(world: &mut World) -> Self
Create a new Resources container, spawning the internal resource entity.
Sourcepub fn insert_resource<T>(&mut self, world: &mut World, res: T)where
T: Component,
pub fn insert_resource<T>(&mut self, world: &mut World, res: T)where
T: Component,
Insert or replace a resource of type T.
Sourcepub fn get_resource<'a, T>(&self, world: &'a World) -> Ref<'a, T>where
T: Component,
pub fn get_resource<'a, T>(&self, world: &'a World) -> Ref<'a, T>where
T: Component,
Borrow resource T, panicking if it is not present.
Sourcepub fn get_resource_mut<'a, T>(&self, world: &'a World) -> RefMut<'a, T>where
T: Component,
pub fn get_resource_mut<'a, T>(&self, world: &'a World) -> RefMut<'a, T>where
T: Component,
Mutably borrow resource T, panicking if it is not present.
Sourcepub fn has_resource<T>(&self, world: &World) -> boolwhere
T: Component,
pub fn has_resource<T>(&self, world: &World) -> boolwhere
T: Component,
Returns true if resource T is currently present.
Sourcepub fn get_command_buffer<'a>(&'a self) -> RefMut<'a, CommandBuffer>
pub fn get_command_buffer<'a>(&'a self) -> RefMut<'a, CommandBuffer>
Borrow the shared command buffer used to defer world mutations.
Sourcepub fn try_insert<T>(&mut self, world: &mut World, res: T) -> boolwhere
T: Component,
pub fn try_insert<T>(&mut self, world: &mut World, res: T) -> boolwhere
T: Component,
Insert resource T only if it is not already present.
Returns true if the resource was inserted, false if it already existed.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Resources
impl !RefUnwindSafe for Resources
impl !Sync for Resources
impl Send for Resources
impl Unpin for Resources
impl UnsafeUnpin for Resources
impl UnwindSafe for Resources
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