Struct StorageWrapper

Source
pub struct StorageWrapper<'a, T, D> { /* private fields */ }
Expand description

A wrapper around the masked storage and the generations vector. Can be used for safe lookup of components, insertions and removes. This is what World::read/write fetches for the user.

Implementations§

Source§

impl<'a, T, D> StorageWrapper<'a, T, D>

Source

pub fn new(data: D, entities: Ref<'a, Entities>) -> Self

Source§

impl<'a, T, D> StorageWrapper<'a, T, D>
where T: Component, D: Deref<Target = MaskedStorage<T>>,

Source

pub fn fetched_entities(&self) -> &Entities

Returns the Entities resource fetched by this storage. This does not have anything to do with the components inside. You only want to use this when implementing additional methods for Storage via an extension trait.

Source

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

Tries to read the data associated with an Entity.

Source

pub fn count(&self) -> usize

Computes the number of elements this Storage contains by counting the bits in the bit set. This operation will never be performed in constant time.

Source

pub fn is_empty(&self) -> bool

Checks whether this Storage is empty. This operation is very cheap.

Source

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

Returns true if the storage has a component for this entity, and that entity is alive.

Source

pub fn mask(&self) -> &BitSet

Returns a reference to the bitset of this storage which allows filtering by the component type without actually getting the component.

Source

pub fn not(&self) -> AntiStorage<'_>

Source§

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

Source

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

Tries to mutate the data associated with an Entity.

Source

pub fn insert( &mut self, entity: Entity, component: T, ) -> Result<Option<T>, Error>

Inserts new data for a given Entity. Returns the result of the operation as a InsertResult<T>

If a component already existed for the given Entity, then it will be overwritten with the new component. If it did overwrite, then the result will contain Some(T) where T is the previous component.

Source

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

Removes the data associated with an Entity.

Source

pub fn clear(&mut self)

Clears the contents of the storage.

Source

pub fn drain(&mut self) -> Drain<'_, T>

Creates a draining storage wrapper which can be .joined to get a draining iterator.

Trait Implementations§

Source§

impl<'a, 'e, T, D> Join for &'a StorageWrapper<'e, T, D>
where T: Component, D: Deref<Target = MaskedStorage<T>>,

Source§

type Mask = &'a BitSet

Type of joined bit mask.
Source§

type Type = &'a T

Type of joined components.
Source§

type Value = &'a <T as Component>::Storage

Type of joined storages.
Source§

unsafe fn open(self) -> (Self::Mask, Self::Value)

Open this join by returning the mask and the storages. Read more
Source§

unsafe fn get(v: &mut Self::Value, i: Index) -> &'a T

Get a joined component value by a given index. Read more
Source§

fn join(self) -> JoinIter<Self>
where Self: Sized,

Create a joined iterator over the contents.
Source§

fn maybe(self) -> MaybeJoin<Self>
where Self: Sized,

Returns a Join-able structure that yields all indices, returning None for all missing elements and Some(T) for found elements. Read more
Source§

fn is_unconstrained() -> bool

If this Join typically returns all indices in the mask, then iterating over only it or combined with other joins that are also dangerous will cause the JoinIter/ParJoin to go through all indices which is usually not what is wanted and will kill performance.
Source§

impl<'a, 'e, T, D> Join for &'a mut StorageWrapper<'e, T, D>
where T: Component, D: DerefMut<Target = MaskedStorage<T>>,

Source§

type Mask = &'a BitSet

Type of joined bit mask.
Source§

type Type = &'a mut T

Type of joined components.
Source§

type Value = &'a <T as Component>::Storage

Type of joined storages.
Source§

unsafe fn open(self) -> (Self::Mask, Self::Value)

Open this join by returning the mask and the storages. Read more
Source§

unsafe fn get(v: &mut Self::Value, i: Index) -> &'a mut T

Get a joined component value by a given index. Read more
Source§

fn join(self) -> JoinIter<Self>
where Self: Sized,

Create a joined iterator over the contents.
Source§

fn maybe(self) -> MaybeJoin<Self>
where Self: Sized,

Returns a Join-able structure that yields all indices, returning None for all missing elements and Some(T) for found elements. Read more
Source§

fn is_unconstrained() -> bool

If this Join typically returns all indices in the mask, then iterating over only it or combined with other joins that are also dangerous will cause the JoinIter/ParJoin to go through all indices which is usually not what is wanted and will kill performance.
Source§

impl<'a, 'e, T, D> Not for &'a StorageWrapper<'e, T, D>
where T: Component, D: Deref<Target = MaskedStorage<T>>,

Source§

type Output = AntiStorage<'a>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl<'a, 'e, T, D> ParJoin for &'a StorageWrapper<'e, T, D>
where T: Component, D: Deref<Target = MaskedStorage<T>>, T::Storage: Sync,

Source§

fn par_join(self) -> JoinParIter<Self>
where Self: Sized,

Source§

impl<'a, 'e, T, D> ParJoin for &'a mut StorageWrapper<'e, T, D>
where T: Component, D: DerefMut<Target = MaskedStorage<T>>, T::Storage: Sync + DistinctStorage,

Source§

fn par_join(self) -> JoinParIter<Self>
where Self: Sized,

Source§

impl<'a, T: Component, D> DistinctStorage for StorageWrapper<'a, T, D>

Auto Trait Implementations§

§

impl<'a, T, D> Freeze for StorageWrapper<'a, T, D>
where D: Freeze,

§

impl<'a, T, D> !RefUnwindSafe for StorageWrapper<'a, T, D>

§

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

§

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

§

impl<'a, T, D> Unpin for StorageWrapper<'a, T, D>
where D: Unpin, T: Unpin,

§

impl<'a, T, D> !UnwindSafe for StorageWrapper<'a, 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<'a, T> DynamicSystemData<'a> for T
where T: SystemData<'a>,

Source§

type Accessor = StaticAccessor<T>

The accessor of the SystemData, which specifies the read and write dependencies and does the fetching.
Source§

fn setup(_: &StaticAccessor<T>, world: &mut World)

Sets up World for fetching this system data.
Source§

fn fetch(_: &StaticAccessor<T>, world: &'a World) -> T

Creates a new resource bundle by fetching the required resources from the World struct. 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> Resource for T
where T: Any + Send + Sync,