Skip to main content

World

Struct World 

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

A minimal ECS supporting entity and component insertion/removal, association, and single-type iteration.

Implementations§

Source§

impl World

Source

pub fn new() -> Self

Create a new ECS instance.

Source

pub fn insert_entity(&mut self) -> EntityKey

Insert a new entity and return the corresponding entity key.

Source

pub fn remove_entity(&mut self, entity_key: EntityKey) -> Option<()>

Remove an entity with the corresponding entity key. If the entity corresponding to the entity key is not found, return an None. Otherwise, return an Some(()).

Source

pub fn contains_entity(&self, entity_key: EntityKey) -> bool

Return entity with the corresponding entity key. If the entity corresponding to the entity key is not found, return an None. Otherwise, return an Some(()).

Source

pub fn iter_entity(&self) -> impl Iterator<Item = EntityKey> + '_

Return an iterator over all entity keys.

Source

pub fn insert_component<T>( &mut self, entity_key: EntityKey, component: T, ) -> Option<()>
where T: Component,

Insert a new component with the corresponding entity key and return the corresponding component key. If the entity corresponding to the entity key is not found, return an None. Otherwise, return an Some(CompKey).

Source

pub fn remove_component<T>(&mut self, entity_key: EntityKey) -> Option<()>
where T: Component,

Remove a component with the corresponding component key and type, and return the component. If the component corresponding to the component key and type is not found, return an None. Otherwise, return an Some(()).

Source

pub fn get_component<T>(&self, entity_key: EntityKey) -> Option<&T>
where T: Component,

Return a component with the corresponding component key and type. If the component corresponding to the component key and type is not found, return an None. Otherwise, return an Some(&T).

Source

pub fn get_component_mut<T>(&mut self, entity_key: EntityKey) -> Option<&mut T>
where T: Component,

Return a mutable component with the corresponding component key and type. If the component corresponding to the component key and type is not found, return an None. Otherwise, return an Some(&mut T).

Source

pub fn iter_component<T>(&self) -> impl Iterator<Item = &T>
where T: Component,

Return an iterator over all components of the corresponding type. If the component type is not found, return an None. Otherwise, return an Some(impl Iterator<Item = &T>).

Source

pub fn iter_component_mut<T>(&mut self) -> impl Iterator<Item = &mut T>
where T: Component,

Return a mutable iterator over all components of the corresponding type. If the component type is not found, return an None. Otherwise, return an Some(impl Iterator<Item = &mut T>).

Trait Implementations§

Source§

impl Debug for World

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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 UnsafeUnpin 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.