1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
extern crate proc_macro;
pub
use TokenStream;
use ;
/// Implement `Bundle` for a struct
///
/// Bundles can be passed directly to `World::spawn` and `World::insert`, and obtained from
/// `World::remove`. Can be convenient when combined with other derives like `serde::Deserialize`.
///
/// # Example
/// ```
/// # use hecs::*;
/// #[derive(Bundle)]
/// struct Foo {
/// x: i32,
/// y: char,
/// }
///
/// let mut world = World::new();
/// let e = world.spawn(Foo { x: 42, y: 'a' });
/// assert_eq!(*world.get::<&i32>(e).unwrap(), 42);
/// ```
/// Implement `DynamicBundleClone` for a struct.
///
/// This is an extension macro for bundles which allow them to be cloned, and
/// subsequently used in `EntityBuilderClone::add_bundle`.
///
/// Requires that all fields of the struct implement [`Clone`].
///
/// The trait Bundle must also be implemented to be able to be used in
/// entity builder.
/// Implement `Query` for a struct or enum.
///
/// Queries can be passed to the type parameter of `World::query`. They must have exactly
/// one lifetime parameter, and all of their fields must be queries (e.g. references) using that
/// lifetime.
///
/// For enum queries, the result will always be the first variant that matches the entity.
/// Unit variants and variants without any fields will always match an entity.
///
/// # Example
/// ```
/// # use hecs::*;
/// #[derive(Query, Debug, PartialEq)]
/// struct Foo<'a> {
/// x: &'a i32,
/// y: &'a mut bool,
/// }
///
/// let mut world = World::new();
/// let e = world.spawn((42, false));
/// assert_eq!(
/// world.query_one_mut::<Foo>(e).unwrap(),
/// Foo {
/// x: &42,
/// y: &mut false
/// }
/// );
/// ```