Trait checs::iter::LendingIterator
source · pub trait LendingIterator: for<'a> Lifetime<'a> {
// Required method
fn next(&mut self) -> Option<<Self as Lifetime<'_>>::Item>;
// Provided method
fn for_each<F>(self, f: F)
where Self: Sized,
F: FnMut(<Self as Lifetime<'_>>::Item) { ... }
}Required Methods§
Provided Methods§
sourcefn for_each<F>(self, f: F)where
Self: Sized,
F: FnMut(<Self as Lifetime<'_>>::Item),
fn for_each<F>(self, f: F)where Self: Sized, F: FnMut(<Self as Lifetime<'_>>::Item),
Examples found in repository?
examples/basic.rs (lines 37-39)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
fn main() {
let mut world = world::World::<Storage>::new();
checs::spawn!(world, Health(80), Position { x: 0, y: 0 }, Visible);
checs::spawn!(world, Position { x: 1, y: 1 }, Visible);
checs::spawn!(world, Position { x: 2, y: 1 });
checs::spawn!(world, Health(100), Position { x: 1, y: 4 }, Visible);
{
let ps = &world.storage.positions;
let hs = &mut world.storage.healths;
let vs = &world.storage.visibles;
let query = (ps, hs, vs).into_query();
query.for_each(|(_, (_, h, _))| {
h.0 += 10;
});
}
println!();
{
let ps = &world.storage.positions;
let hs = &world.storage.healths;
let vs = &world.storage.visibles;
let query = (ps, hs, vs).into_query();
query.for_each(|(e, (p, h, v))| {
println!("{e:?} is {v:?} at ({}, {}) with {} HP", p.x, p.y, h.0);
});
}
}