Enum StorageEntry

Source
pub enum StorageEntry<'a, 'b, T, D>
where 'b: 'a, T: 'a, D: 'a,
{ Occupied(OccupiedEntry<'a, 'b, T, D>), Vacant(VacantEntry<'a, 'b, T, D>), }
Expand description

Entry to a storage for convenient filling of components or removal based on whether the entity has a component.

Variants§

§

Occupied(OccupiedEntry<'a, 'b, T, D>)

Entry variant that is returned if the entity has a component.

§

Vacant(VacantEntry<'a, 'b, T, D>)

Entry variant that is returned if the entity does not have a component.

Implementations§

Source§

impl<'a, 'b, T, D> StorageEntry<'a, 'b, T, D>
where T: Component, D: DerefMut<Target = MaskedStorage<T>>,

Source

pub fn or_insert(self, component: T) -> &'a mut T

Inserts a component if the entity does not have it already.

Source

pub fn or_insert_with<F>(self, default: F) -> &'a mut T
where F: FnOnce() -> T,

Inserts a component using a lazily called function that is only called when inserting the component. Ensures this entry has a value and if not, inserts one using the result of the passed closure. Returns a reference to the value afterwards.

Auto Trait Implementations§

§

impl<'a, 'b, T, D> Freeze for StorageEntry<'a, 'b, T, D>

§

impl<'a, 'b, T, D> !RefUnwindSafe for StorageEntry<'a, 'b, T, D>

§

impl<'a, 'b, T, D> Send for StorageEntry<'a, 'b, T, D>
where D: Send, T: Send,

§

impl<'a, 'b, T, D> Sync for StorageEntry<'a, 'b, T, D>
where D: Sync, T: Sync,

§

impl<'a, 'b, T, D> Unpin for StorageEntry<'a, 'b, T, D>

§

impl<'a, 'b, T, D> !UnwindSafe for StorageEntry<'a, 'b, T, D>

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> Any for T
where T: Any,

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.
Source§

impl<T> Erased for T

Source§

impl<T> Event for T
where T: Send + Sync + 'static,

Source§

impl<T> Resource for T
where T: Any + Send + Sync,