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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//! Types defining resources within a [`World`].
//!
//! A resource can be thought of as a singleton [`Component`]. A resource is not associated with an
//! entity. It can be queried alongside entities to allow storing and retrieving data relevant to
//! the `World`.
//!
//! Storing data as resources within a `World` allows that data to be accessed safely by multiple
//! [`System`]s within a [`Schedule`].
//!
//! # Example
//! ```
//! use brood::{
//! resources,
//! Registry,
//! World,
//! };
//!
//! // Define resource types.
//! #[derive(Debug, PartialEq)]
//! struct Foo(u32);
//! #[derive(Debug, PartialEq)]
//! struct Bar(bool);
//!
//! // Define a world containing the resources.
//! let mut world = World::<Registry!(), _>::with_resources(resources!(Foo(0), Bar(true)));
//!
//! // Resources can be viewed.
//! assert_eq!(world.get::<Foo, _>(), &Foo(0));
//!
//! // Resources can be mutated.
//! world.get_mut::<Bar, _>().0 = false;
//! assert_eq!(world.get::<Bar, _>(), &Bar(false));
//! ```
//!
//! [`Component`]: crate::component::Component
//! [`Schedule`]: crate::system::Schedule
//! [`System`]: crate::system::System
//! [`World`]: crate::World
pub
pub use ;
pub use Deserialize;
pub use Debug;
pub use Serialize;
pub use Claims;
pub use Deserializer;
pub use Debugger;
pub use Serializer;
use cratedefine_null;
use Any;
use Length;
use Sealed;
define_null!;
/// A single resource.
///
/// A resource is like a singleton component. It is not associated with any entity. It can be
/// queried alongside entities to allow storing and retrieving data relevant to the [`World`].
///
/// # Example
/// ```
/// use brood::{
/// resources,
/// Registry,
/// World,
/// };
///
/// // Define a resource.
/// #[derive(Debug, PartialEq)]
/// struct Resource(u32);
///
/// // Define a world containing the resource.
/// let mut world = World::<Registry!(), _>::with_resources(resources!(Resource(0)));
///
/// // The resource can be mutated.
/// world.get_mut::<Resource, _>().0 = 42;
///
/// assert_eq!(world.get::<Resource, _>(), &Resource(42));
/// ```
///
/// [`World`]: crate::World
/// A heterogeneous list of resources.
///
/// When resources are stored within a [`World`], they are stored in a heterogeneous list. This
/// allows any combination of resources to be easily stored and accessed.
///
/// While duplicate `Resource` types can be included in a list of resources, it is not advised.
/// There are no benefits to including multiple `Resource`s, and it will likely break some resource
/// queries at compile-time whose APIs have been designed based on the assumption that no
/// duplicates will exist.
///
/// # Example
/// ```
/// use brood::Resources;
///
/// // Define some resources;
/// struct Foo(usize);
/// struct Bar(bool);
///
/// type Resources = Resources!(Foo, Bar);
/// ```
///
/// [`World`]: crate::World
/// Creates a list of resources.
///
/// This should be used when defining a [`World`] with resources.
///
/// # Example
/// ```
/// use brood::{
/// resources,
/// Registry,
/// Resources,
/// World,
/// };
///
/// struct A(u32);
/// struct B(char);
///
/// let world = World::<Registry!(), Resources!(A, B)>::with_resources(resources!(A(42), B('a')));
/// ```
///
/// [`World`]: crate::World
/// Defines the type of a list of resources.
///
/// This should be used when defining a [`World`] with resources.
///
/// # Example
/// ```
/// use brood::{
/// resources,
/// Registry,
/// Resources,
/// World,
/// };
///
/// struct A(u32);
/// struct B(char);
///
/// let world = World::<Registry!(), Resources!(A, B)>::with_resources(resources!(A(42), B('a')));
/// ```
///
/// [`World`]: crate::World