Struct hecs::View

source · []
pub struct View<'q, Q: Query> { /* private fields */ }
Expand description

Provides random access to the results of a query

Implementations

Retrieve the query results corresponding to entity

Will yield None if the entity does not exist or does not match the query.

Does not require exclusive access to the map, but is defined only for queries yielding only shared references.

Retrieve the query results corresponding to entity

Will yield None if the entity does not exist or does not match the query.

Like get_mut, but allows simultaneous access to multiple entities

Safety

Must not be invoked while any unique borrow of the fetched components of entity is live.

Like get_mut, but allows checked simultaneous access to multiple entities

For N > 3, the check for distinct entities will clone the array and take O(N log N) time.

Examples
let mut world = World::new();

let a = world.spawn((1, 1.0));
let b = world.spawn((2, 4.0));
let c = world.spawn((3, 9.0));

let mut query = world.query_mut::<&mut i32>();
let mut view = query.view();
let [a,b,c] = view.get_mut_n([a, b, c]);

assert_eq!(*a.unwrap(), 1);
assert_eq!(*b.unwrap(), 2);
assert_eq!(*c.unwrap(), 3);

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.