@@ -560,7 +560,17 @@ pub fn derive_event(input: TokenStream) -> TokenStream {
560
560
component:: derive_event ( input)
561
561
}
562
562
563
- /// Implement the `EntityEvent` trait.
563
+ /// Cheat sheet for derive syntax,
564
+ /// see full explanation on `EntityEvent` trait docs.
565
+ ///
566
+ /// ```ignore
567
+ /// #[derive(Event, EntityEvent)]
568
+ /// /// Traversal component
569
+ /// #[entity_event(traversal = &'static ChildOf)]
570
+ /// /// Always propagate
571
+ /// #[entity_event(auto_propagate)]
572
+ /// struct MyEvent;
573
+ /// ```
564
574
#[ proc_macro_derive( EntityEvent , attributes( entity_event) ) ]
565
575
pub fn derive_entity_event ( input : TokenStream ) -> TokenStream {
566
576
component:: derive_entity_event ( input)
@@ -578,7 +588,89 @@ pub fn derive_resource(input: TokenStream) -> TokenStream {
578
588
component:: derive_resource ( input)
579
589
}
580
590
581
- /// Implement the `Component` trait.
591
+ /// Cheat sheet for derive syntax,
592
+ /// see full explanation and examples on the `Component` trait doc.
593
+ ///
594
+ /// ## Immutability
595
+ /// ```ignore
596
+ /// #[derive(Component)]
597
+ /// #[component(immutable)]
598
+ /// struct MyComponent;
599
+ /// ```
600
+ ///
601
+ /// ## Sparse instead of table-based storage
602
+ /// ```ignore
603
+ /// #[derive(Component)]
604
+ /// #[component(storage = "SparseSet")]
605
+ /// struct MyComponent;
606
+ /// ```
607
+ ///
608
+ /// ## Required Components
609
+ ///
610
+ /// ```ignore
611
+ /// #[derive(Component)]
612
+ /// #[require(
613
+ /// // `Default::default()`
614
+ /// A,
615
+ /// // tuple structs
616
+ /// B(1),
617
+ /// // named-field structs
618
+ /// C {
619
+ /// x: 1,
620
+ /// ..default()
621
+ /// },
622
+ /// // unit structs/variants
623
+ /// D::One,
624
+ /// // associated consts
625
+ /// E::ONE,
626
+ /// // constructors
627
+ /// F::new(1),
628
+ /// // arbitrary expressions
629
+ /// G = make(1, 2, 3)
630
+ /// )]
631
+ /// struct MyComponent;
632
+ /// ```
633
+ ///
634
+ /// ## Relationships
635
+ /// ```ignore
636
+ /// #[derive(Component)]
637
+ /// #[relationship(relationship_target = Children)]
638
+ /// pub struct ChildOf {
639
+ /// // Marking the field is not necessary if there is only one.
640
+ /// #[relationship]
641
+ /// pub parent: Entity,
642
+ /// internal: u8,
643
+ /// };
644
+ ///
645
+ /// #[derive(Component)]
646
+ /// #[relationship_target(relationship = ChildOf)]
647
+ /// pub struct Children(Vec<Entity>);
648
+ /// ```
649
+ ///
650
+ /// On despawn, also despawn all related entities:
651
+ /// ```ignore
652
+ /// #[derive(Component)]
653
+ /// #[relationship_target(relationship_target = Children, linked_spawn)]
654
+ /// pub struct Children(Vec<Entity>);
655
+ /// ```
656
+ ///
657
+ /// ## Hooks
658
+ /// ```ignore
659
+ /// #[derive(Component)]
660
+ /// #[component(hook_name = function)]
661
+ /// struct MyComponent;
662
+ /// ```
663
+ /// where `hook_name` is `on_add`, `on_insert`, `on_replace` or `on_remove`;
664
+ /// `function` can be either a path, e.g. `some_function::<Self>`,
665
+ /// or a function call that returns a function that can be turned into
666
+ /// a `ComponentHook`, e.g. `get_closure("Hi!")`.
667
+ ///
668
+ /// ## Ignore this component when cloning an entity
669
+ /// ```ignore
670
+ /// #[derive(Component)]
671
+ /// #[component(clone_behavior = Ignore)]
672
+ /// struct MyComponent;
673
+ /// ```
582
674
#[ proc_macro_derive(
583
675
Component ,
584
676
attributes( component, require, relationship, relationship_target, entities)
0 commit comments