Struct specs::storage::Storage [−][src]
pub struct Storage<'e, T, D> { /* fields omitted */ }
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
pub fn entry<'a>(
&'a mut self,
e: Entity
) -> Result<StorageEntry<'a, 'e, T, D>, WrongGeneration> where
'e: 'a,
[src]
pub fn entry<'a>(
&'a mut self,
e: Entity
) -> Result<StorageEntry<'a, 'e, T, D>, WrongGeneration> where
'e: 'a,
[src]Returns an entry to the component associated to the entity.
Behaves somewhat similarly to std::collections::HashMap
’s entry api.
Example
if let Ok(entry) = storage.entry(entity) { entry.or_insert(Comp { field: 55 }); }
Returns a Join
-able structure that yields all indices, returning
Entry
for all elements
WARNING: Do not have a join of only Entries
s. Otherwise the join will
iterate over every single index of the bitset. If you want a join with
all Entries
s, add an EntitiesRes
to the join as well to bound the
join to all entities that are alive.
Example
for (mut counter, _) in (counters.entries(), &marker).join() { let counter = counter.or_insert_with(Default::default); counter.increase(); if counter.reached_limit() { counter.reset(); // Do something } }
pub fn restrict<'rf>(
&'rf self
) -> RestrictedStorage<'rf, 'st, T, &T::Storage, &BitSet, ImmutableParallelRestriction>
[src]
pub fn restrict<'rf>(
&'rf self
) -> RestrictedStorage<'rf, 'st, T, &T::Storage, &BitSet, ImmutableParallelRestriction>
[src]Builds an immutable RestrictedStorage
out of a Storage
. Allows
deferred unchecked access to the entity’s component.
This is returned as a ParallelRestriction
version since you can only
get immutable components with this which is safe for parallel by
default.
impl<'st, T, D> Storage<'st, T, D> where
T: Component,
D: DerefMut<Target = MaskedStorage<T>>,
[src]
impl<'st, T, D> Storage<'st, T, D> where
T: Component,
D: DerefMut<Target = MaskedStorage<T>>,
[src]pub fn restrict_mut<'rf>(
&'rf mut self
) -> RestrictedStorage<'rf, 'st, T, &mut T::Storage, &BitSet, SequentialRestriction>
[src]
pub fn restrict_mut<'rf>(
&'rf mut self
) -> RestrictedStorage<'rf, 'st, T, &mut T::Storage, &BitSet, SequentialRestriction>
[src]Builds a mutable RestrictedStorage
out of a Storage
. Allows
restricted access to the inner components without allowing
invalidating the bitset for iteration in Join
.
pub fn par_restrict_mut<'rf>(
&'rf mut self
) -> RestrictedStorage<'rf, 'st, T, &mut T::Storage, &BitSet, MutableParallelRestriction>
[src]
pub fn par_restrict_mut<'rf>(
&'rf mut self
) -> RestrictedStorage<'rf, 'st, T, &mut T::Storage, &BitSet, MutableParallelRestriction>
[src]Builds a mutable, parallel RestrictedStorage
,
does not allow mutably getting other components
aside from the current iteration.
Returns the event channel tracking modified components.
Returns the actual state of the event emission.
Returns the event channel for insertions/removals/modifications of this storage’s components.
Starts tracking component events. Note that this reader id should be used every frame, otherwise events will pile up and memory use by the event channel will grow waiting for this reader.
Flags an index with a ComponentEvent
.
Controls the events signal emission. When this is set to false the events modified/inserted/removed are not emitted.
Creates a new Storage
from a fetched allocator and a immutable or
mutable MaskedStorage
, named data
.
Gets the wrapped storage.
Returns the EntitiesRes
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.
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.
Checks whether this Storage
is empty. This operation is very cheap.
Returns true if the storage has a component for this entity, and that entity is alive.
Returns the component data as a slice.
The indices of this slice may not correspond to anything in particular. Check the underlying storage documentation for details.
Gets mutable access to the wrapped storage.
Safety
This is unsafe because modifying the wrapped storage without also updating the mask bitset accordingly can result in illegal memory access.
Tries to mutate the data associated with an Entity
.
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.
Trait Implementations
Open this join by returning the mask and the storages. Read more
Get a joined component value by a given index. Read more
Create a joined iterator over the contents.
Returns a Join
-able structure that yields all indices, returning
None
for all missing elements and Some(T)
for found elements. Read more
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. Read more
Open this join by returning the mask and the storages. Read more
Get a joined component value by a given index. Read more
Create a joined iterator over the contents.
Returns a Join
-able structure that yields all indices, returning
None
for all missing elements and Some(T)
for found elements. Read more
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. Read more
Create a joined parallel iterator over the contents.
impl<'a, 'e, T, D> ParJoin for &'a mut Storage<'e, T, D> where
T: Component,
D: DerefMut<Target = MaskedStorage<T>>,
T::Storage: Sync + DistinctStorage,
[src]
impl<'a, 'e, T, D> ParJoin for &'a mut Storage<'e, T, D> where
T: Component,
D: DerefMut<Target = MaskedStorage<T>>,
T::Storage: Sync + DistinctStorage,
[src]Create a joined parallel iterator over the contents.
impl<'a, T: Component, D> DistinctStorage for Storage<'a, T, D> where
T::Storage: DistinctStorage,
[src]Auto Trait Implementations
impl<'e, T, D> !RefUnwindSafe for Storage<'e, T, D>
impl<'e, T, D> !UnwindSafe for Storage<'e, T, D>
Blanket Implementations
impl<T> Any for T where
T: Any,
impl<T> Any for T where
T: Any,
pub fn get_type_id(&self) -> TypeId
Mutably borrows from an owned value. Read more
type Accessor = StaticAccessor<T>
type Accessor = StaticAccessor<T>
The accessor of the SystemData
, which specifies the read and write
dependencies and does the fetching. Read more
Sets up World
for fetching this system data.