 89cbc78d3d
			
		
	
	
		89cbc78d3d
		
			
		
	
	
	
	
		
			
			# Objective Be consistent with `Resource`s and `Components` and have `Event` types be more self-documenting. Although not susceptible to accidentally using a function instead of a value due to `Event`s only being initialized by their type, much of the same reasoning for removing the blanket impl on `Resource` also applies here. * Not immediately obvious if a type is intended to be an event * Prevent invisible conflicts if the same third-party or primitive types are used as events * Allows for further extensions (e.g. opt-in warning for missed events) ## Solution Remove the blanket impl for the `Event` trait. Add a derive macro for it. --- ## Changelog - `Event` is no longer implemented for all applicable types. Add the `#[derive(Event)]` macro for events. ## Migration Guide * Add the `#[derive(Event)]` macro for events. Third-party types used as events should be wrapped in a newtype.
		
			
				
	
	
		
			32 lines
		
	
	
		
			1013 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			1013 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use bevy_ecs::{event::Event, prelude::Entity};
 | |
| 
 | |
| /// An [`Event`] that is fired whenever there is a change in the world's hierarchy.
 | |
| ///
 | |
| /// [`Event`]: bevy_ecs::event::Event
 | |
| #[derive(Event, Debug, Clone, PartialEq, Eq)]
 | |
| pub enum HierarchyEvent {
 | |
|     /// Fired whenever an [`Entity`] is added as a child to a parent.
 | |
|     ChildAdded {
 | |
|         /// The child that was added
 | |
|         child: Entity,
 | |
|         /// The parent the child was added to
 | |
|         parent: Entity,
 | |
|     },
 | |
|     /// Fired whenever a child [`Entity`] is removed from its parent.
 | |
|     ChildRemoved {
 | |
|         /// The child that was removed
 | |
|         child: Entity,
 | |
|         /// The parent the child was removed from
 | |
|         parent: Entity,
 | |
|     },
 | |
|     /// Fired whenever a child [`Entity`] is moved to a new parent.
 | |
|     ChildMoved {
 | |
|         /// The child that was moved
 | |
|         child: Entity,
 | |
|         /// The parent the child was removed from
 | |
|         previous_parent: Entity,
 | |
|         /// The parent the child was added to
 | |
|         new_parent: Entity,
 | |
|     },
 | |
| }
 |