Struct World

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

Sparse typed storage with generational entities and checked component borrows.

RefCell deliberately makes World !Sync. Parallel mutation should use separate worlds or explicit synchronization around the whole world.

Implementations§

Source§

impl World

Source

pub fn new() -> Self

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn contains(&self, entity: Entity) -> bool

Source

pub fn spawn<B: Bundle>(&mut self, bundle: B) -> Entity

Spawns one entity containing zero to four components. Panics if a bundle repeats a component type; no entity is allocated in that case.

Source

pub fn try_spawn<B: Bundle>(&mut self, bundle: B) -> Result<Entity, Error>

Source

pub fn despawn(&mut self, entity: Entity) -> Result<(), Error>

Drops every component and invalidates the handle before reusing its slot.

Source

pub fn insert<B: Bundle>( &mut self, entity: Entity, bundle: B, ) -> Result<(), Error>

Inserts or replaces a bundle’s components. Other components remain unchanged. Invalid identities and duplicate bundle types are rejected before any writes.

Source

pub fn remove<T: 'static>(&mut self, entity: Entity) -> Result<T, Error>

Source

pub fn has<T: 'static>(&self, entity: Entity) -> bool

Source

pub fn get<A: Access>(&self, entity: Entity) -> Result<A::Item<'_>, Error>

Reads or mutates a typed component through an explicit access type. Use get::<&T> or get::<&mut T>; returned guards enforce runtime aliasing.

Source

pub fn get_mut<T: 'static>( &self, entity: Entity, ) -> Result<RefMut<'_, T>, Error>

Source

pub fn query<Q: Query>(&self) -> QueryBorrow<'_, Q>

Queries up to four component access types, optionally including Entity. Repeated shared access is valid; any repeated mutable access is rejected.

Source

pub fn try_query<Q: Query>(&self) -> Result<QueryBorrow<'_, Q>, Error>

Source

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

Live identities in stable slot order, without borrowing any components.

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.