VecStorage

Struct VecStorage 

Source
pub struct VecStorage<T> { /* private fields */ }
Expand description

A storage type that stores components in a contiguous Vec.

Implementations§

Source§

impl<T> VecStorage<T>

Source

pub fn new(entities: Arc<RwLock<Entities>>, capacity: u32) -> Self

Create a new VecStorage with the specified initial capacity.

Source

pub fn get(&self, entity: Entity) -> Option<&T>

Get a reference to the component associated with the given entity in self, if any.

Source

pub fn get_mut(&mut self, entity: Entity) -> Option<&mut T>

Get a mutable reference to the component associated with the given entity in self, if any.

Source

pub fn set( &mut self, entity: Entity, data: T, ) -> Result<Option<T>, NoSuchEntity>

Set the component for the given entity. Returns Err(NoSuchEntity) if the given entity doesn’t exist. Otherwise, returns Ok(data), where data is previous data evicted by this operation (if any).

Source

pub fn remove_unchecked(&mut self, entity: Entity) -> Option<T>

Remove the component for the given entity. Returns the previous data associated with the given entity in self. Does not check if the entity exists; only use this if you know it exists, e.g. through invariants in your code or because you retrieved this in a loop iterating over all alive entities.

Source

pub fn remove(&mut self, entity: Entity) -> Result<Option<T>, NoSuchEntity>

Remove the component for the given entity. Returns the previous data associated with the given entity in self.

Source

pub fn clear(&mut self)

Remove the data stored in self for all entities.

Trait Implementations§

Source§

impl<T: Debug> Debug for VecStorage<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for VecStorage<T>

§

impl<T> RefUnwindSafe for VecStorage<T>
where T: RefUnwindSafe,

§

impl<T> Send for VecStorage<T>
where T: Send,

§

impl<T> Sync for VecStorage<T>
where T: Sync,

§

impl<T> Unpin for VecStorage<T>
where T: Unpin,

§

impl<T> UnwindSafe for VecStorage<T>
where T: UnwindSafe,

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.