examples/queries/
query_wildcard.rs1use crate::z_ignore_test_common::*;
2
3use flecs_ecs::prelude::*;
4pub use flecs_ecs::{core::*, macros::Component};
5
6#[derive(Component)]
7pub struct EatsAmount {
8 pub amount: i32,
9}
10
11#[derive(Component)]
12pub struct Apples;
13
14#[derive(Component)]
15pub struct Pears;
16
17fn main() {
18 let world = World::new();
19
20 let query = world.new_query::<&(EatsAmount, flecs::Wildcard)>();
22
23 world
25 .entity_named("Bob")
26 .set_pair::<EatsAmount, Apples>(EatsAmount { amount: 10 })
27 .set_pair::<EatsAmount, Pears>(EatsAmount { amount: 5 });
28
29 world
30 .entity_named("Alice")
31 .set_pair::<EatsAmount, Apples>(EatsAmount { amount: 4 });
32
33 query.each_iter(|it, index, eats| {
36 let entity = it.entity(index);
37 let pair = it.pair(0);
38 let food = pair.second_id();
39
40 println!("{} eats {} {}", entity, eats.amount, food);
41 });
42
43 }
48
49#[cfg(feature = "flecs_nightly_tests")]
50#[test]
51fn test() {
52 let output_capture = OutputCapture::capture().unwrap();
53 main();
54 output_capture.test("query_wildcard".to_string());
55}