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]
T: Component,
R: Borrow<T::Storage>,
B: Borrow<BitSet>,
pub fn get(&self, entity: Entity) -> Option<&T>
[src]
Attempts to get the component related to the entity.
Functions similar to the normal Storage::get
implementation.
pub fn get_unchecked(&self, entry: &Entry<'rf, T>) -> &T
[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]
T: Component,
R: BorrowMut<T::Storage>,
B: Borrow<BitSet>,
pub fn get_mut_unchecked(&mut self, entry: &Entry<'rf, T>) -> &mut T
[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]
T: Component,
R: BorrowMut<T::Storage>,
B: Borrow<BitSet>,
pub fn get_mut(&mut self, entity: Entity) -> Option<&mut T>
[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]
T: Component,
R: BorrowMut<T::Storage> + 'rf,
B: Borrow<BitSet> + 'rf,
fn par_join(self) -> JoinParIter<Self> where
Self: Sized,
[src]
Self: Sized,
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]
T: Component,
R: Borrow<T::Storage> + 'rf,
B: Borrow<BitSet> + 'rf,
fn par_join(self) -> JoinParIter<Self> where
Self: Sized,
[src]
Self: Sized,
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]
T: Component,
R: Borrow<T::Storage>,
B: Borrow<BitSet>,
type Type = (Entry<'rf, T>, Self)
Type of joined components.
type Value = Self
Type of joined storages.
type Mask = &'rf BitSet
Type of joined bit mask.
fn open(self) -> (Self::Mask, Self::Value)
[src]
Open this join by returning the mask and the storages.
unsafe fn get(value: &mut Self::Value, id: Index) -> Self::Type
[src]
Get a joined component value by a given index.
fn join(self) -> JoinIter<Self> where
Self: Sized,
[src]
Self: Sized,
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]
T: Component,
R: BorrowMut<T::Storage>,
B: Borrow<BitSet>,
type Type = (Entry<'rf, T>, Self)
Type of joined components.
type Value = Self
Type of joined storages.
type Mask = BitSet
Type of joined bit mask.
fn open(self) -> (Self::Mask, Self::Value)
[src]
Open this join by returning the mask and the storages.
unsafe fn get(value: &mut Self::Value, id: Index) -> Self::Type
[src]
Get a joined component value by a given index.
fn join(self) -> JoinIter<Self> where
Self: Sized,
[src]
Self: Sized,
Create a joined iterator over the contents.