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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
//! Component traits are tags and pairs that can be added to components to modify their behavior.
use *;
/// Marker trait for Flecs component traits.
// Component traits
/// A relationship can be marked with the `Acyclic` trait to indicate that it cannot contain cycles.
/// Both the builtin `ChildOf` and `IsA` relationships are marked acyclic. Knowing whether a relationship
/// is acyclic allows the storage to detect and throw errors when a cyclic relationship is introduced by accident.
///
/// Note that because cycle detection requires expensive algorithms, adding `Acyclic` to a relationship does not
/// guarantee that an error will be thrown when a cycle is accidentally introduced. While detection may improve
/// over time, an application that runs without errors is no guarantee that it does not contain acyclic
/// relationships with cycles.
;
impl_component_trait!;
/// The `CanToggle` trait allows a component to be toggled. Component toggling can (temporarily) disable a
/// component, which excludes it from queries. Component toggling can be used as a cheaper alternative to
/// adding/removing as toggling relies on setting a bitset, and doesn't require the entity to be moved between
/// tables. Component toggling can also be used to restore a component with its old value.
///
/// Queries treat a disabled component as if the entity doesn't have it. `CanToggle` components add a small
/// amount of overhead to query evaluation, even for entities that did not toggle their component.
///
/// # Example
/// ```rust
/// # use flecs_ecs::prelude::*;
///
/// # #[derive(Component)]
/// # struct Position {
/// # x: f32,
/// # y: f32,
/// # }
///
/// # let world = World::new();
///
/// world
/// .component::<Position>()
/// .add_trait::<flecs::CanToggle>();
///
/// let e = world.entity().set(Position { x: 10.0, y: 20.0 });
///
/// e.disable(Position::id()); // Disable component
/// assert!(!e.is_enabled(Position::id()));
///
/// e.enable(Position::id()); // Enable component
/// assert!(e.is_enabled(Position::id()));
/// ```
;
impl_component_trait!;
/// Cleanup traits ensure that the store does not contain any dangling references when entities are deleted.
///
/// When entities that are used as tags, components, relationships or relationship targets are deleted,
/// cleanup traits ensure that the store does not contain any dangling references. Any cleanup policy
/// provides this guarantee, so while they are configurable, applications cannot configure traits that
/// allow for dangling references.
///
/// **Note**: this only applies to entities (like tags, components, relationships) that are added _to_
/// other entities. It does not apply to components that store an entity value, so:
///
/// ```no_run
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// # let parent = world.entity();
/// # let e = world.entity();
/// #[derive(Component)]
/// struct MyComponent {
/// e: Entity, // Not covered by cleanup traits
/// }
///
/// e.child_of(parent); // Covered by cleanup traits
/// ```
///
/// The default policy is that any references to the entity will be **removed**. For example, when the
/// tag `Archer` is deleted, it will be removed from all entities that have it. Which is similar to invoking
/// the [`World::remove_all()`](flecs_ecs::core::World::remove_all) method.
///
/// Since entities can be used in relationship pairs, just calling `remove_all` on just the entity itself
/// does not guarantee that no dangling references are left. A more comprehensive description of what happens is:
///
/// ```
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// # let archer = world.entity();
/// world.remove_all(archer);
/// world.remove_all((archer, flecs::Wildcard));
/// world.remove_all((flecs::Wildcard, archer));
/// ```
///
/// This succeeds in removing all possible references to `Archer`. Sometimes this behavior is not what we want however.
/// Consider a parent-child hierarchy, where we want to delete the child entities when the parent is deleted.
/// Instead of removing `(ChildOf, parent)` from all children, we need to *delete* the children.
///
/// We also want to specify this per relationship. If an entity has `(Likes, parent)` we may not want to delete that entity,
/// meaning the cleanup we want to perform for `Likes` and `ChildOf` may not be the same.
///
/// This is what cleanup traits are for: to specify which action needs to be executed under which condition.
/// They are applied *to* entities that have a reference to the entity being deleted:
/// if I delete the `Archer` tag I remove the tag *from* all entities that have it.
///
/// To configure a cleanup policy for an entity, a `(Condition, Action)` pair can be added to it.
/// If no policy is specified, the default cleanup action (`Remove`) is performed.
///
/// There are three cleanup actions:
/// - [`Remove`]: as if doing `remove_all(entity)` (default)
/// - [`Delete`]: as if doing `delete_with(entity)`
/// - [`Panic`]: throw a fatal error (default for components)
///
/// There are two cleanup conditions:
/// - [`OnDelete`]: the component, tag or relationship is deleted
/// - [`OnDeleteTarget`]: a target used with the relationship is deleted
///
/// Policies apply to both regular and pair instances, so to all entities with `T` as well as `(T, *)`.
///
/// # Cleanup order
///
/// While cleanup actions allow for specifying what needs to happen when a particular entity is deleted,
/// or when an entity used with a particular relationship is deleted, they do not enforce a strict cleanup *order*.
/// The reason for this is that there can be many orderings that satisfy the cleanup traits.
///
/// This is important to consider especially when writing `OnRemove` triggers or hooks,
/// as the order in which they are invoked highly depends on the order in which entities are cleaned up.
///
/// Take an example with a parent and a child that both have the `Node` tag:
///
/// ```rust
/// # use flecs_ecs::prelude::*;
/// # #[derive(Component)]
/// # struct Node;
/// # let world = World::new();
/// world
/// .observer::<flecs::OnRemove, ()>()
/// .with(Node)
/// .each_entity(|e, _| {
/// // This observer will be invoked when a Node is removed
/// });
///
/// let p = world.entity().add(Node);
/// let c = world.entity().add(Node).child_of(p);
/// ```
///
/// In this example, when calling `p.destruct()` the observer is first invoked for the child, and then for the parent,
/// which is to be expected as the child is deleted before the parent.
/// Cleanup traits do not however guarantee that this is always the case.
///
/// An application could also call `world.component::<Node>().destruct()` which would delete the `Node` component and
/// all of its instances. In this scenario the cleanup traits for the `flecs::ChildOf` relationship are not considered,
/// and therefore the ordering is undefined. Another typical scenario in which ordering is undefined is when an application
/// has cyclical relationships with a `Delete` cleanup action.
///
/// #### Cleanup order during world teardown
/// Cleanup issues often show up during world teardown as the ordering in which entities are deleted is controlled by the application.
/// While world teardown respects cleanup traits, there can be many entity delete orderings that are valid according to the cleanup traits,
/// but not all of them are equally useful. There are ways to organize entities that helps world cleanup to do the right thing. These are:
///
/// **Organize components, triggers, observers and systems in modules.**
/// Storing these entities in modules ensures that they stay alive for as long as possible.
/// This leads to more predictable cleanup ordering as components will be deleted as their entities are,
/// vs. when the component is deleted. It also ensures that triggers and observers are not deleted while matching events are still being generated.
///
/// **Avoid organizing components, triggers, observers and systems under entities that are not modules**.
/// If a non-module entity with children is stored in the root, it will get cleaned up along with other regular entities.
/// If you have entities such as these organized in a non-module scope, consider adding the `flecs::Module` tag to the root of that scope.
///
/// The next section goes into more detail on why this improves cleanup behavior and what happens during world teardown.
///
/// #### World teardown sequence
/// To understand why some ways to organize entities work better than others, having an overview of what happens during world teardown is useful.
/// Here is a list of the steps that happen when a world is deleted:
///
/// 1. **Find all root entities**
/// World teardown starts by finding all root entities, which are entities that do not have the builtin `ChildOf` relationship.
/// Note that empty entities (entities without any components) are not found during this step.
///
/// 2. **Query out modules, components, observers and systems**
/// This ensures that components are not cleaned up before the entities that use them, and triggers,
/// observers and systems are not cleaned up while there are still conditions under which they could be invoked.
///
/// 3. **Query out entities that have no children**
/// If entities have no children they cannot cause complex cleanup logic. This also decreases the likelihood of initiating cleanup actions that could impact other entities.
///
/// 4. **Delete root entities**
/// The root entities that were not filtered out will be deleted.
///
/// 5. **Delete everything else**
/// The last step will delete all remaining entities. At this point cleanup traits are no longer considered and cleanup order is undefined.
pub use *;
/// The `DontFragment` trait uses the same sparse storage as the `Sparse` trait, but does not fragment tables.
/// This can be desirable especially if a component or relationship is very sparse (e.g. it is only added to a
/// few entities) as this would otherwise result in many tables that only contain a small number of entities.
///
/// The following code example shows how to mark a component as `DontFragment`:
///
/// # Example
/// ```no_run
/// # use flecs_ecs::prelude::*;
/// #[derive(Component)]
/// #[flecs(traits(DontFragment))]
/// struct Position {
/// x: f32,
/// y: f32,
/// }
/// # let world = World::new();
///
/// // or
/// world
/// .component::<Position>()
/// .add_trait::<flecs::DontFragment>();
/// ```
///
/// Components with the `DontFragment` trait have the following limitations:
/// - They don't show up in types [`Archetype`](flecs_ecs::core::Archetype)
/// - Monitors don't trigger on `DontFragment` components. The reason for this is that monitors compare the
/// previous table with the current table of an entity to determine if an entity started matching, and
/// `DontFragment` components aren't part of the table.
///
/// Support for `DontFragment` has a number of (temporary) limitations:
/// - `target_for` does not yet work for `DontFragment` components.
/// - `DontFragment` components are not serialized yet to JSON (and don't show up in the explorer).
/// - `Or`, `Optional`, `AndFrom` and `NotFrom` operators are not yet supported.
/// - Component inheritance and transitivity are not yet supported.
/// - Queries for `DontFragment` components may run slower than expected.
///
/// What does work:
/// - ECS operations (`add`, `remove`, `get`, `get_mut`, `ensure`, `emplace`, `set`, `delete`).
/// - Relationships (including `Exclusive` relationships).
/// - Simple component queries.
/// - Wildcard queries.
/// - Queries with variables.
;
impl_component_trait!;
/// The `Exclusive` trait enforces that an entity can have only a single instance of a relationship. When a
/// second instance is added, it replaces the first instance. An example of a relationship with the `Exclusive`
/// trait is the builtin `ChildOf` relationship.
///
/// # Usage Example
/// ```no_run
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// # let e = world.entity();
/// # let parent_a = world.entity();
/// # let parent_b = world.entity();
/// e.child_of(parent_a);
/// e.child_of(parent_b); // replaces (ChildOf, parent_a)
/// ```
///
/// to create a custom exclusive relationship, add the `Exclusive` trait to it:
/// ```
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// let married_to = world.entity().add_trait::<flecs::Exclusive>();
/// ```
;
impl_component_trait!;
/// Entities can be annotated with the `Final` trait, which prevents using them with `IsA` relationship.
/// This is similar to the concept of a final class as something that cannot be extended.
///
/// # Example
/// ```
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// let e = world.entity().add_trait::<flecs::Final>();
///
/// // not allowed
/// // let i = world.entity().is_a(e);
/// ```
///
/// Queries may use the final trait to optimize, as they do not have to explore subsets of a final entity.
;
impl_component_trait!;
/// The `Inheritable` trait indicates that a component can be inherited from (it can be used as target of an
/// `IsA` relationship). It is not required to add this trait to components before using them as target of an
/// `IsA` pair, but it can be used to ensure that queries for the component take into account component inheritance.
///
/// # Example
/// ```
/// # use flecs_ecs::prelude::*;
/// # #[derive(Component)]
/// # struct Unit;
/// # #[derive(Component)]
/// # struct Warrior;
/// # let world = World::new();
/// world.component::<Unit>().add_trait::<flecs::Inheritable>();
///
/// let q = world.query::<()>().with(Unit).build();
///
/// world.component::<Warrior>().is_a(Unit::id());
///
/// q.each_entity(|e, _| {
/// // ...
/// });
/// ```
///
/// Queries must be aware of (potential) inheritance relationships when they are created. A query will be
/// created with support for inheritance under the following conditions:
/// - If the component has the `Inheritable` trait
/// - If the component inherits from another component and is not `Final`
///
/// If a query was not aware of inheritance relationships at creation time and one or more of the components
/// in the query were inherited from, query iteration will fail in debug mode.
;
impl_component_trait!;
/// The `OneOf` trait enforces that the target of the relationship is a child of a specified entity. `OneOf`
/// can be used to indicate that the target needs to be either a child of the relationship (common for enum
/// relationships), or of another entity.
///
/// # Example - Constrain target to child of relationship
/// ```
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
///
/// // Enforce that target of relationship is child of Food
/// let food = world.entity().add_trait::<flecs::OneOf>();
/// let apples = world.entity().child_of(food);
/// let fork = world.entity();
///
/// // This is ok, Apples is a child of Food
/// let a = world.entity().add((food, apples));
///
/// // not allowed - Fork is not a child of Food
/// // let b = world.entity().add((food, fork));
/// ```
///
/// # Example - Constrain target to child of another entity
/// The following example shows how `OneOf` can be used to enforce that the relationship
/// target is the child of an entity other than the relationship:
/// ```
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
///
/// // Enforce that target of relationship is child of Food
/// let food = world.entity();
/// let eats = world.entity().add((flecs::OneOf::id(), food));
/// let apples = world.entity().child_of(food);
/// let fork = world.entity();
///
/// // This is ok, Apples is a child of Food
/// let a = world.entity().add((eats, apples));
///
/// // not allowed - Fork is not a child of Food
/// // let b = world.entity().add((eats, fork));
/// ```
;
impl_component_trait!;
/// `OnInstantiate` traits configure component behavior during entity instantiation.
///
/// The `OnInstantiate` trait configures the behavior of components when an entity is instantiated from
/// another entity (usually a prefab). Instantiation happens when an `IsA` pair is added to an entity.
///
/// By default, when an entity is instantiated, the components from the base entity (the `IsA` target)
/// are copied to the instance. This behavior can be modified with the `OnInstantiate` trait, which can
/// be used as a pair in combination with three targets:
///
/// | Target | Description |
/// |--------|-------------|
/// | [`Override`] | Copy component from base to instance (default) |
/// | [`Inherit`] | Inherit component from base |
/// | [`DontInherit`] | Don't inherit (and don't copy) component from base |
pub use *;
/// The `OrderedChildren` trait can be added to entities to indicate that creation order or a custom order should be preserved.
///
/// When this trait is added to a parent, the entity ids returned by the [`EntityView::each_child`](flecs_ecs::core::EntityView::each_child) operations will be in creation or custom order.
/// Children of a parent with the `OrderedChildren` trait are guaranteed to be returned in a single result.
///
/// The trait does not affect the order in which entities are returned by queries.
///
/// The stored order can be modified by an application with the [`EntityView::set_child_order`](flecs_ecs::core::EntityView::set_child_order) operation.
///
/// # Example
/// ```rust
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// # #[derive(Component)]
/// # struct Position { x: f32, y: f32 }
/// let parent = world.entity().add_trait::<flecs::OrderedChildren>();
///
/// let child_1 = world.entity().child_of(parent);
/// let child_2 = world.entity().child_of(parent);
/// let child_3 = world.entity().child_of(parent);
///
/// // Adding/removing components usually changes the order in which children are
/// // iterated, but with the OrderedChildren trait order is preserved.
/// child_2.set(Position { x: 10.0, y: 20.0 });
///
/// parent.each_child(|child| {
/// // 1st result: child_1
/// // 2nd result: child_2
/// // 3rd result: child_3
/// });
/// ```
;
impl_component_trait!;
/// A relationship can be marked with `PairIsTag` in which case a pair with the relationship will never contain data.
/// By default the data associated with a pair is determined by whether either the relationship or target are components.
/// For some relationships however, even if the target is a component, no data should be added to the relationship.
///
/// # Example
/// TODO
;
impl_component_trait!;
/// Component trait. Enforces that an entity can only be used as a relationship.
///
/// # Example
///
/// ```rust, no_run
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// #[derive(Component)]
/// struct Likes;
///
/// #[derive(Component)]
/// struct Apples;
///
/// world
/// .component::<Likes>()
/// .add_trait::<flecs::Relationship>();
///
/// let e = world
/// .entity()
/// // .add(Likes::id()) // Panic, 'Likes' is not used as relationship
/// // .add((Apples::id(), Likes::id())) // Panic, 'Likes' is not used as relationship, but as target
/// .add((Likes::id(), Apples::id())); // OK
/// ```
///
/// Entities marked with `Relationship` may still be used as target if the relationship part of the pair has the `Trait` trait.
/// This ensures the relationship can still be used to configure the behavior of other entities.
///
/// # Example
///
/// ```rust
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// #[derive(Component)]
/// struct Likes;
///
/// #[derive(Component)]
/// struct Loves;
///
/// world
/// .component::<Likes>()
/// .add_trait::<flecs::Relationship>();
///
/// // Even though Likes is marked as relationship and used as target here, this
/// // won't panic as With is marked as trait.
/// world
/// .component::<Loves>()
/// .add_trait::<(flecs::With, Likes)>();
/// ```
;
impl_component_trait!;
/// A relationship can be marked reflexive which means that a query like `Relationship(Entity, Entity)` should evaluate to true.
/// The utility of `Reflexive` becomes more obvious with an example:
///
/// Given this dataset:
/// ```ignore
/// IsA(Oak, Tree)
/// ```
///
/// we can ask whether an oak is a tree:
/// ```ignore
/// IsA(Oak, Tree)
/// - Yes, an Oak is a tree (Oak has (IsA, Tree))
/// ```
///
/// We can also ask whether a tree is a tree, which it obviously is:
/// ```ignore
/// IsA(Tree, Tree)
/// - Yes, even though Tree does not have (IsA, Tree)
/// ```
///
/// However, this does not apply to all relationships. Consider a dataset with a `LocatedIn` relationship:
///
/// ```ignore
/// LocatedIn(SanFrancisco, UnitedStates)
/// ```
///
/// we can now ask whether `SanFrancisco` is located in `SanFrancisco`, which it is not:
/// ```ignore
/// LocatedIn(SanFrancisco, SanFrancisco)
/// - No
/// ```
///
/// In these examples, `IsA` is a reflexive relationship, whereas `LocatedIn` is not.
;
impl_component_trait!;
/// The `Singleton` trait enforces that a component can only be instantiated once in the world.
/// A singleton component can only be added to the entity that is associated with the component.
/// This happens automatically when using the singleton APIs:
///
/// # Example
///
/// ```rust
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// # #[derive(Component)]
/// # struct TimeOfDay(f32);
/// world
/// .component::<TimeOfDay>()
/// .add_trait::<flecs::Singleton>();
///
/// world.set(TimeOfDay(0.0));
/// ```
///
/// Attempting to add the component to other entities beside itself will panic.
///
/// When a query is created for a component with the `Singleton` trait,
/// the query will automatically match the singleton component on the component entity.
/// This is the same as specifying the component itself as source for the term:
///
/// ```rust
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// # #[derive(Component)]
/// # struct Position { x: f32, y: f32 }
/// # #[derive(Component)]
/// # struct Velocity { x: f32, y: f32 }
/// # #[derive(Component)]
/// # struct TimeOfDay(f32);
/// // Automatically matches TimeOfDay as singleton
/// let q = world.new_query::<(&Position, &Velocity, &TimeOfDay)>();
///
/// // Is the same as
/// let q = world
/// .query::<(&Position, &Velocity, &TimeOfDay)>()
/// .term_at(2)
/// .set_src(TimeOfDay::id())
/// .build();
/// ```
;
impl_component_trait!;
/// The `Sparse` trait configures a component to use sparse storage.
/// Sparse components are stored outside of tables, which means they do not have to be moved.
/// Sparse components are also guaranteed to have stable pointers, which means that a component pointer
/// is not invalidated when an entity moves to a new table. ECS operations and queries work as expected with sparse components.
///
/// Sparse components trade in query speed for component add/remove speed.
/// Adding and removing sparse components still requires an archetype change.
///
/// They also enable storage of non-movable components.
///
/// # Example
/// adding the trait
/// ```rust
/// # use flecs_ecs::prelude::*;
/// # #[derive(Component)]
/// # struct Position { x: f32, y: f32 }
/// # let world = World::new();
/// world.component::<Position>().add_trait::<flecs::Sparse>();
/// ```
;
impl_component_trait!;
/// The `Symmetric` trait enforces that when a relationship `(R, Y)` is added to entity `X`, the relationship
/// `(R, X)` will be added to entity `Y`. The reverse is also true, if relationship `(R, Y)` is removed from `X`,
/// relationship `(R, X)` will be removed from `Y`.
///
/// The symmetric trait is useful for relationships that do not make sense unless they are bidirectional.
/// Examples of such relationships are `AlliesWith`, `MarriedTo`, `TradingWith` and so on.
///
/// # Example
/// ```
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// let married_to = world.entity().add_trait::<flecs::Symmetric>();
/// let bob = world.entity();
/// let alice = world.entity();
/// bob.add((married_to, alice)); // Also adds (MarriedTo, Bob) to Alice
/// ```
;
impl_component_trait!;
/// The target trait enforces that an entity can only be used as relationship target.
///
/// # Example
/// ```
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// #[derive(Component)]
/// struct Likes;
///
/// #[derive(Component)]
/// struct Apples;
///
/// world.component::<Apples>().add_trait::<flecs::Target>();
///
/// let e = world
/// .entity()
/// // .add(Apples::id()) // Panic, 'Apples' is not used as target
/// // .add((Apples::id(), Likes::id())) // Panic, 'Apples' is not used as target, but as relationship
/// .add((Likes::id(), Apples::id())); // OK
/// ```
;
impl_component_trait!;
/// The trait trait marks an entity as a trait, which is any tag that is added to another tag/component/relationship
/// to modify its behavior. All traits in this manual are marked as trait. It is not required to mark a trait as
/// a trait before adding it to another tag/component/relationship. The main reason for the trait trait is to ease
/// some of the constraints on relationships (see the [`Relationship`] trait).
///
/// # Example
/// ```
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// #[derive(Component)]
/// struct Serializable;
///
/// world
/// .component::<Serializable>()
/// .add_trait::<flecs::Trait>();
/// ```
;
impl_component_trait!;
/// Relationships can be marked as transitive. A formal-ish definition of transitivity in the context of
/// relationships is:
///
/// ```text
/// If Relationship(EntityA, EntityB)
/// And Relationship(EntityB, EntityC)
/// Then Relationship(EntityA, EntityC)
/// ```
///
/// What this means becomes more obvious when translated to a real-life example:
///
/// > If Manhattan is located in New York, and New York is located in the USA, then Manhattan is located in the USA.
///
/// In this example, `LocatedIn` is the relationship and `Manhattan`, `New York` and `USA` are entities `A`, `B` and `C`.
/// Another common example of transitivity is found in OOP inheritance:
///
/// > If a Square is a Rectangle and a Rectangle is a Shape, then a Square is a Shape.
///
/// In this example `IsA` is the relationship and `Square`, `Rectangle` and `Shape` are the entities.
///
/// When relationships in Flecs are marked as transitive, queries can follow the transitive relationship to see
/// if an entity matches.
///
/// # Example
/// ```
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// let locatedin = world.entity();
/// let manhattan = world.entity();
/// let newyork = world.entity();
/// let usa = world.entity();
///
/// // Make the LocatedIn relationship transitive
/// locatedin.add_trait::<flecs::Transitive>();
///
/// manhattan.add((locatedin, newyork));
/// newyork.add((locatedin, usa));
///
/// // Now querying for (LocatedIn, USA) will match both NewYork and Manhattan
/// ```
///
/// If we were to query for `(LocatedIn, USA)` without making it transitive, we would only match `NewYork`,
/// because we never added `(LocatedIn, USA)` to `Manhattan`. By adding the transitive trait to the relationship
/// entity, queries will follow the `LocatedIn` relationship and return both `NewYork` and `Manhattan`.
;
impl_component_trait!;
/// Traversable relationships are allowed to be traversed automatically by queries, for example using the
/// `up` traversal (upwards traversal). Traversable relationships are also marked as [`Acyclic`], which ensures
/// a query won't accidentally attempt to traverse a relationship that contains cycles.
///
/// Events are propagated along the edges of traversable relationships. A typical example of this is when a
/// component value is changed on a prefab. The event of this change will be propagated by traversing the `IsA`
/// relationship downwards, for all instances of the prefab. Event propagation does not happen for relationships
/// that are not marked with `Traversable`.
;
impl_component_trait!;
/// The `With` relationship can be added to components to indicate that it must always come together with
/// another component.
///
/// # Example - With regular components/tags
/// ```rust
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// let responsibility = world.entity();
/// let power = world.entity().add((flecs::With, responsibility));
///
/// // Create new entity that has both Power and Responsibility
/// let e = world.entity().add(power);
/// ```
///
/// When the `With` relationship is added to a relationship, the additional id added to the entity will be
/// a relationship pair as well, with the same target as the original relationship:
///
/// # Example - With relationships
/// ```rust
/// # use flecs_ecs::prelude::*;
/// # let world = World::new();
/// let likes = world.entity();
/// let loves = world.entity().add((flecs::With::id(), likes));
/// let pears = world.entity();
///
/// // Create new entity with both (Loves, Pears) and (Likes, Pears)
/// let e = world.entity().add((loves, pears));
/// ```
;
impl_component_trait!;