Struct rs_ecs::World[][src]

pub struct World { /* fields omitted */ }
Expand description

The ECS world storing Entity and components.

Implementations

impl World[src]

pub fn new() -> Self[src]

Create an empty world.

impl World[src]

#[must_use]
pub fn alloc(&mut self) -> Entity
[src]

Create an Entity without any components. To add components, see Self::insert().

Example

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (42_u32, true));

pub fn free(&mut self, ent: Entity)[src]

Remove an Entity and all its components from the world. To remove components, see Self::remove().

Example

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (42_u32, true));

world.free(entity);

impl World[src]

pub fn insert<B>(&mut self, ent: Entity, comps: B) where
    B: Bundle, 
[src]

Insert components for a given Entity.

Panics

Panics if one of the components is already present for the entity.

Example

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (42_u32, true));
world.insert(entity, (String::from("Hello"),));

pub fn remove<B>(&mut self, ent: Entity) -> Option<B> where
    B: Bundle, 
[src]

Remove components for a given Entity.

Example

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (42_u32, true, String::from("Hello")));

world.remove::<(u32, bool)>(entity).unwrap();
world.remove::<(String,)>(entity).unwrap();

impl World[src]

pub fn contains<C>(&self, ent: Entity) -> bool where
    C: 'static, 
[src]

Check if a certain component type is present for an Entity.

Example

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (42_u32, true));

assert!(world.contains::<u32>(entity));

pub fn get<C>(&self, ent: Entity) -> Option<Comp<'_, C>> where
    C: 'static, 
[src]

Get an immutable reference to the component of the given type for an Entity.

Example

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (42_u32, true));

let comp = world.get::<u32>(entity).unwrap();

pub fn get_mut<C>(&self, ent: Entity) -> Option<CompMut<'_, C>> where
    C: 'static, 
[src]

Get a mutable reference to the component of the given type for an Entity.

Example

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (42_u32, true));

let comp = world.get_mut::<u32>(entity).unwrap();

Trait Implementations

impl Default for World[src]

fn default() -> Self[src]

Create an empty world.

Auto Trait Implementations

impl !RefUnwindSafe for World

impl !Send for World

impl !Sync for World

impl Unpin for World

impl UnwindSafe for World

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.