pub struct World { /* private fields */ }
Implementations§
Source§impl World
impl World
pub fn new() -> Self
Sourcepub fn add_resource(&mut self, resource: impl Any)
pub fn add_resource(&mut self, resource: impl Any)
Add a resource.
use ecs_lib_rs::World;
let mut world = World::new();
world.add_resource(1_u32);
assert_eq!(world.get_resource::<u32>(), Some(&1));
Sourcepub fn get_resource<T: Any>(&self) -> Option<&T>
pub fn get_resource<T: Any>(&self) -> Option<&T>
Query for a resource and get a reference to it. The type of the resource must be added in so that it can find it.
use ecs_lib_rs::World;
let mut world = World::new();
assert_eq!(world.get_resource::<u32>(), None);
world.add_resource(1_u32);
assert_eq!(world.get_resource::<u32>(), Some(&1));
Sourcepub fn get_resource_mut<T: Any>(&mut self) -> Option<&mut T>
pub fn get_resource_mut<T: Any>(&mut self) -> Option<&mut T>
Query for a resource and get a mutable reference to it. The type of the resource must be added in so that it can find it.
use ecs_lib_rs::World;
let mut world = World::new();
assert_eq!(world.get_resource_mut::<u32>(), None);
world.add_resource(1_u32);
{
let x = world.get_resource_mut::<u32>();
assert_eq!(x, Some(&mut 1_u32));
let x = x.unwrap();
*x += 1;
}
assert_eq!(world.get_resource::<u32>(), Some(&2));
Sourcepub fn remove_resource<T: Any>(&mut self) -> Option<Box<dyn Any>>
pub fn remove_resource<T: Any>(&mut self) -> Option<Box<dyn Any>>
Removes the resource from the world. Returns None
if the resource wasn’t present and hence was not deleted.
Otherwise, it returns Some(data)
use ecs_lib_rs::World;
let mut world = World::new();
world.add_resource(1_u32);
world.remove_resource::<u32>();
assert_eq!(world.get_resource::<u32>(), None);
Sourcepub fn register_component<T: Any>(&mut self)
pub fn register_component<T: Any>(&mut self)
Register a component. The type of the resource must be added in so that it can find it.
use ecs_lib_rs::World;
let mut world = World::new();
world.register_component::<u32>();
pub fn create_entity(&mut self) -> &mut Entities
pub fn query(&self) -> Query<'_>
pub fn delete_component_by_entity_id<T: Any>(&mut self, id: usize) -> Result<()>
pub fn add_component_to_entity_by_id( &mut self, id: usize, component: impl Any, ) -> Result<()>
pub fn delete_entity_by_id(&mut self, id: usize) -> Result<()>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for World
impl !RefUnwindSafe for World
impl !Send for World
impl !Sync for World
impl Unpin for World
impl !UnwindSafe for World
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