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> Freeze for JoinLendIter<J>
impl<J> RefUnwindSafe for JoinLendIter<J>
impl<J> Send for JoinLendIter<J>
impl<J> Sync for JoinLendIter<J>
impl<J> Unpin for JoinLendIter<J>
impl<J> UnwindSafe for JoinLendIter<J>
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more