Struct specs::join::JoinLendIter
source · pub struct JoinLendIter<J: LendJoin> { /* private fields */ }
Expand description
JoinLendIter
is an is a lending/streaming iterator over components from a
group of storages.
Implementations§
source§impl<J: LendJoin> JoinLendIter<J>
impl<J: LendJoin> JoinLendIter<J>
source§impl<J: LendJoin> JoinLendIter<J>
impl<J: LendJoin> JoinLendIter<J>
sourcepub fn next(&mut self) -> Option<LendJoinType<'_, J>>
pub fn next(&mut self) -> Option<LendJoinType<'_, J>>
Lending next
.
Can be used to iterate with this pattern:
while let Some(components) = join_lending_iter.next() {
sourcepub fn for_each(self, f: impl FnMut(LendJoinType<'_, J>))
pub fn for_each(self, f: impl FnMut(LendJoinType<'_, J>))
Calls a closure on each entity in the join.
sourcepub fn get(
&mut self,
entity: Entity,
entities: &Entities<'_>
) -> Option<LendJoinType<'_, J>>where
J: RepeatableLendGet,
pub fn get( &mut self, entity: Entity, entities: &Entities<'_> ) -> Option<LendJoinType<'_, J>>where J: RepeatableLendGet,
Allows getting joined values for specific entity.
Example
let mut world = World::new();
world.register::<Pos>();
world.register::<Vel>();
// This entity could be stashed anywhere (into `Component`, `Resource`, `System`s data, etc.) as it's just a number.
let entity = world
.create_entity()
.with(Pos)
.with(Vel)
.build();
// Later
{
let mut pos = world.write_storage::<Pos>();
let vel = world.read_storage::<Vel>();
assert_eq!(
Some((&mut Pos, &Vel)),
(&mut pos, &vel).lend_join().get(entity, &world.entities()),
"The entity that was stashed still has the needed components and is alive."
);
}
// The entity has found nice spot and doesn't need to move anymore.
world.write_storage::<Vel>().remove(entity);
// Even later
{
let mut pos = world.write_storage::<Pos>();
let vel = world.read_storage::<Vel>();
assert_eq!(
None,
(&mut pos, &vel).lend_join().get(entity, &world.entities()),
"The entity doesn't have velocity anymore."
);
}
sourcepub fn get_unchecked(&mut self, index: Index) -> Option<LendJoinType<'_, J>>where
J: RepeatableLendGet,
pub fn get_unchecked(&mut self, index: Index) -> Option<LendJoinType<'_, J>>where J: RepeatableLendGet,
Allows getting joined values for specific raw index.
The raw index for an Entity
can be retrieved using Entity::id
method.
As this method operates on raw indices, there is no check to see if the entity is still alive, so the caller should ensure it instead.
Note: Not checking is still sound (thus this method is safe to call), but this can return data from deleted entities!
Auto Trait Implementations§
impl<J> RefUnwindSafe for JoinLendIter<J>where <J as LendJoin>::Mask: RefUnwindSafe, <J as LendJoin>::Value: RefUnwindSafe,
impl<J> Send for JoinLendIter<J>where <J as LendJoin>::Mask: Send, <J as LendJoin>::Value: Send,
impl<J> Sync for JoinLendIter<J>where <J as LendJoin>::Mask: Sync, <J as LendJoin>::Value: Sync,
impl<J> Unpin for JoinLendIter<J>where <J as LendJoin>::Mask: Unpin, <J as LendJoin>::Value: Unpin,
impl<J> UnwindSafe for JoinLendIter<J>where <J as LendJoin>::Mask: UnwindSafe, <J as LendJoin>::Value: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more