pub struct Storage<'e, 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

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 Entriess. Otherwise the join will iterate over every single index of the bitset. If you want a join with all Entriess, 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
    }
}

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.

Builds a mutable RestrictedStorage out of a Storage. Allows restricted access to the inner components without allowing invalidating the bitset for iteration in Join.

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

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.

Tries to read the data associated with an Entity.

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 a reference to the bitset of this storage which allows filtering by the component type without actually getting the component.

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.

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.

Removes the data associated with an Entity.

Clears the contents of the storage.

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Type of joined bit mask.

Type of joined components.

Type of joined storages.

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

Type of joined bit mask.

Type of joined components.

Type of joined storages.

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

The resulting type after applying the ! operator.

Performs the unary ! operation. Read more

Create a joined parallel iterator over the contents.

Create a joined parallel iterator over the contents.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

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.

Creates a new resource bundle by fetching the required resources from the World struct. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.