//! Component events. use std::fmt::{Debug, Formatter}; use std::marker::PhantomData; use ecs_macros::Component; use crate::component::Component; /// Event emitted when: /// a) A entity with component `ComponentT` is spawned. /// b) A component `ComponentT` is added to a entity. #[derive(Clone, Component)] pub struct Added where ComponentT: Component, { _pd: PhantomData, } impl Debug for Added where ComponentT: Component, { fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result { formatter .debug_struct("Added") .field("_pd", &self._pd) .finish() } } impl Default for Added where ComponentT: Component, { fn default() -> Self { Self { _pd: PhantomData } } } /// Event emitted when: /// a) A `ComponentT` component is removed from a entity. /// b) A entity with component `ComponentT` is despawned. #[derive(Clone, Component)] pub struct Removed where ComponentT: Component, { _pd: PhantomData, } impl Debug for Removed where ComponentT: Component, { fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result { formatter .debug_struct("Removed") .field("_pd", &self._pd) .finish() } } impl Default for Removed where ComponentT: Component, { fn default() -> Self { Self { _pd: PhantomData } } } /// Specifies a kind of component event UID. #[derive(Debug, Clone, Copy)] #[non_exhaustive] pub enum Kind { Removed, }