Struct specs::RestrictedStorage [] [src]

pub struct RestrictedStorage<'rf, 'st: 'rf, B, T, R, RT> where
    T: Component,
    R: Borrow<T::Storage> + 'rf,
    B: Borrow<BitSet> + 'rf, 
{ /* fields omitted */ }

Similar to a MaskedStorage and a Storage combined, but restricts usage to only getting and modifying the components. That means nothing that would modify the inner bitset so the iteration cannot be invalidated. For example, no insertion or removal is allowed.

Example Usage:

struct SomeComp(u32);
impl Component for SomeComp {
    type Storage = VecStorage<Self>;
}

struct RestrictedSystem;
impl<'a> System<'a> for RestrictedSystem {
    type SystemData = (
        Entities<'a>,
        WriteStorage<'a, SomeComp>,
    );
    fn run(&mut self, (entities, mut some_comps): Self::SystemData) {
        for (entity, (mut entry, restricted)) in (
            &*entities,
            &mut some_comps.restrict_mut()
        ).join() {
            // Check if the reference is fine to mutate.
            if restricted.get_unchecked(&entry).0 < 5 {
                // Get a mutable reference now.
                let mut mutable = restricted.get_mut_unchecked(&mut entry);
                mutable.0 += 1;
            }
        }
    }
}

Methods

impl<'rf, 'st, B, T, R, RT> RestrictedStorage<'rf, 'st, B, T, R, RT> where
    T: Component,
    R: Borrow<T::Storage>,
    B: Borrow<BitSet>, 
[src]

[src]

Attempts to get the component related to the entity.

Functions similar to the normal Storage::get implementation.

[src]

Gets the component related to the current entry without checking whether the storage has it or not.

impl<'rf, 'st, B, T, R, RT> RestrictedStorage<'rf, 'st, B, T, R, RT> where
    T: Component,
    R: BorrowMut<T::Storage>,
    B: Borrow<BitSet>, 
[src]

[src]

Gets the component related to the current entry without checking whether the storage has it or not.

impl<'rf, 'st, B, T, R> RestrictedStorage<'rf, 'st, B, T, R, NormalRestriction> where
    T: Component,
    R: BorrowMut<T::Storage>,
    B: Borrow<BitSet>, 
[src]

[src]

Attempts to get the component related to the entity mutably.

Functions similar to the normal Storage::get_mut implementation.

Note: This only works if this is a non-parallel RestrictedStorage.

Trait Implementations

impl<'rf, 'st: 'rf, B, T, R> ParJoin for &'rf mut RestrictedStorage<'rf, 'st, B, T, R, ParallelRestriction> where
    T: Component,
    R: BorrowMut<T::Storage> + 'rf,
    B: Borrow<BitSet> + 'rf, 
[src]

[src]

Create a joined parallel iterator over the contents.

impl<'rf, 'st: 'rf, B, T, R> ParJoin for &'rf RestrictedStorage<'rf, 'st, B, T, R, ParallelRestriction> where
    T: Component,
    R: Borrow<T::Storage> + 'rf,
    B: Borrow<BitSet> + 'rf, 
[src]

[src]

Create a joined parallel iterator over the contents.

impl<'rf, 'st: 'rf, B, T, R, RT> Join for &'rf RestrictedStorage<'rf, 'st, B, T, R, RT> where
    T: Component,
    R: Borrow<T::Storage>,
    B: Borrow<BitSet>, 
[src]

Type of joined components.

Type of joined storages.

Type of joined bit mask.

[src]

Open this join by returning the mask and the storages.

[src]

Get a joined component value by a given index.

[src]

Create a joined iterator over the contents.

impl<'rf, 'st: 'rf, B, T, R, RT> Join for &'rf mut RestrictedStorage<'rf, 'st, B, T, R, RT> where
    T: Component,
    R: BorrowMut<T::Storage>,
    B: Borrow<BitSet>, 
[src]

Type of joined components.

Type of joined storages.

Type of joined bit mask.

[src]

Open this join by returning the mask and the storages.

[src]

Get a joined component value by a given index.

[src]

Create a joined iterator over the contents.