Struct World

Source
pub struct World { /* private fields */ }

Implementations§

Source§

impl World

Source

pub fn new() -> Self

Source

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));
Source

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));
Source

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));
Source

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);
Source

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>();
Source

pub fn create_entity(&mut self) -> &mut Entities

Source

pub fn query(&self) -> Query<'_>

Source

pub fn delete_component_by_entity_id<T: Any>(&mut self, id: usize) -> Result<()>

Source

pub fn add_component_to_entity_by_id( &mut self, id: usize, component: impl Any, ) -> Result<()>

Source

pub fn delete_entity_by_id(&mut self, id: usize) -> Result<()>

Trait Implementations§

Source§

impl Default for World

Source§

fn default() -> World

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.