use std::any::Any; use std::sync::Arc; use crate::{ services::clock::{ClockKind, ClockPayload, ClockTicker}, Message, }; pub mod clock; /// Route key a module subscribes with; `Clock(kind)` selects the ticker. #[derive(Clone, Copy, PartialEq, Eq)] pub enum Service { Clock(ClockKind), } impl Service { pub fn subscription(&self) -> iced::Subscription { match self { Self::Clock(_) => ClockTicker::run(), } } } /// A service event with a typed payload. The app only reads /// `key()` for fan-out; the consuming module downcasts the payload. #[derive(Clone, Debug)] pub enum ServicePayloadKind { Clock(ClockPayload), } impl ServicePayloadKind { /// Route key for this event. One arm per kind — adding a service /// touches only this match, never the routing code. pub fn key(&self) -> Service { match self { Self::Clock(payload) => Service::Clock(payload.kind), } } /// Erases the typed payload for the module to downcast. pub fn into_payload(self) -> Arc { match self { Self::Clock(payload) => Arc::new(payload), } } }