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>

source

pub fn new(j: J) -> Self

Create a new lending join iterator.

source§

impl<J: LendJoin> JoinLendIter<J>

source

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() {

source

pub fn for_each(self, f: impl FnMut(LendJoinType<'_, J>))

Calls a closure on each entity in the join.

source

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."
    );
}
source

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Event for Twhere T: Send + Sync + 'static,

source§

impl<T> Resource for Twhere T: Any + Send + Sync,