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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/// A macro to generate a newtype wrapper for [`EntityView`][crate::core::EntityView] with various utility implementations.
///
/// This macro takes the full struct definition as input, so you can define the visibility of the struct and its fields
/// however you like. It also provides implementations for common traits like `Deref`, `DerefMut`, `From`, `Debug`
/// and `Display` to make working with the new type seamless.
///
/// # Parameters
///
/// - `$struct_vis`: The visibility of the struct (e.g., `pub`).
/// - `$struct_def`: The name of the struct being defined.
/// - `$field_vis`: The visibility of the inner field (e.g., `pub`).
///
/// # Generated Code
///
/// - Implements `Deref` and `DerefMut` traits to allow easy access to the underlying `EntityView`.
/// - Implements `From` for conversions between the newtype and `EntityView`.
/// - Provides `Debug` and `Display` implementations for better formatting support.
///
/// # Example Usage & Compile test
///
/// ```rust
/// use flecs_ecs::newtype_of_entity_view;
/// use flecs_ecs::prelude::*;
/// newtype_of_entity_view!(pub struct MyEntityView1(EntityView)); // public w/ private field
/// newtype_of_entity_view!(pub struct MyEntityView2(pub EntityView)); // public w/ public field
/// newtype_of_entity_view!(struct MyEntityView3(pub EntityView)); // private w/ public field
/// newtype_of_entity_view!(struct MyEntityView4(EntityView)); // private w/ private field
/// newtype_of_entity_view!(pub(crate) struct MyEntityView5(pub EntityView)); // public(crate) w/ public field
/// ```
}
};
}
/// A macro to generate a newtype wrapper for [`Entity`][crate::core::Entity] with various utility implementations.
///
/// This macro takes the full struct definition as input, so you can define the visibility of the struct and its fields
/// however you like. It also provides implementations for common traits like `Deref`, `DerefMut`, `From`, `Debug`
/// and `Display` to make working with the new type seamless.
///
/// # Parameters
///
/// - `$struct_vis`: The visibility of the struct (e.g., `pub`).
/// - `$name`: The name of the struct being defined.
/// - `$field_vis`: The visibility of the inner field (e.g., `pub`).
///
/// # Generated Code
///
/// - Implements `Deref` and `DerefMut` traits to allow easy access to the underlying `Entity`.
/// - Implements `From` for conversions between the newtype and `Entity`.
/// - Provides `Debug` and `Display` implementations for better formatting support.
///
/// # Example Usage & Compile test
///
/// ```rust
/// use flecs_ecs::newtype_of_entity;
/// use flecs_ecs::prelude::*;
/// newtype_of_entity!(pub struct MyEntity1(Entity)); // public w/ private field
/// newtype_of_entity!(pub struct MyEntity2(pub Entity)); // public w/ public field
/// newtype_of_entity!(struct MyEntity3(pub Entity)); // private w/ public field
/// newtype_of_entity!(struct MyEntity4(Entity)); // private w/ private field
/// newtype_of_entity!(pub(crate) struct MyEntity5(pub Entity)); // public(crate) w/ public field
/// ```
}
};
}
/// A macro to generate newtype wrappers for both [`Entity`][crate::core::Entity] and [`EntityView`][crate::core::EntityView] with various utility implementations.
/// It uses the macros [`newtype_of_entity`] and [`newtype_of_entity_view`] internally to generate the newtypes.
///
/// This macro takes the full struct definitions for both the entity and the view newtypes, allowing you to define the visibility of each struct and its fields.
/// It provides implementations for common traits such as `Deref`, `DerefMut`, `From`, `Debug`, and `Display`, and also implements conversion methods between the entity and view types.
///
/// # Parameters
///
/// - `$entity_struct_vis`: The visibility of the entity struct (e.g., `pub`).
/// - `$entity_name`: The name of the entity struct being defined.
/// - `$entity_field_vis`: The visibility of the inner field of the entity (e.g., `pub`).
/// - `$view_struct_vis`: The visibility of the view struct (e.g., `pub`).
/// - `$view_name`: The name of the view struct being defined.
/// - `$view_field_vis`: The visibility of the inner field of the view (e.g., `pub`).
///
/// # Generated Code
///
/// - A struct named `$entity_name` is created, wrapping an [`Entity`][crate::core::Entity].
/// - A struct named `$view_name` is created, wrapping an [`EntityView`][crate::core::EntityView].
/// - Implements methods to convert between the entity and view newtypes (`entity.view(world)` and `view.id()`).
/// - Implements `From` for conversions between `$view_name` and `$entity_name`.
///
/// # Example Usage
///
/// ```rust
/// use flecs_ecs::newtype_of_entity_and_view;
/// use flecs_ecs::prelude::*;
///
/// newtype_of_entity_and_view!(
/// pub struct MyEntity(pub Entity),
/// pub struct MyEntityView(pub EntityView)
/// );
///
/// let world = World::new();
/// let entity = world.entity();
///
/// let my_entity = MyEntity(entity.id());
/// let my_entity_view = my_entity.view(&world);
/// let my_entity_from_view: MyEntity = my_entity_view.into();
/// ```
}
// Implement method to convert entity to view
// Implement method to convert view to entity
};
}