This commit is contained in:
2026-09-09 16:56:02 +01:00
parent b9c7e73824
commit 8696425590
2 changed files with 19 additions and 7 deletions
+15 -5
View File
@@ -1,14 +1,24 @@
//! Service registry: turns a route key into the subscription that backs it.
//! Adding a service is a new crate under `crates/services/` plus one arm in
//! `subscription` — core never changes.
//! the impl below — core never changes.
use iced::Subscription;
use common::{Service, ServicePayloadKind};
/// The subscription backing a route key.
pub fn subscription(service: &Service) -> Subscription<ServicePayloadKind> {
match service {
Service::Clock(_) => service_datetime::ClockTicker::run(),
/// Conversion from a route key to the subscription backing it.
///
/// An extension trait (not `impl From<Service> for Subscription<...>`) because
/// both `Service` and `Subscription` are foreign to this crate — the orphan
/// rule blocks a foreign trait (`From`) on a foreign type (`Subscription`).
pub trait IntoSubscription {
fn into_subscription(self) -> Subscription<ServicePayloadKind>;
}
impl IntoSubscription for Service {
fn into_subscription(self) -> Subscription<ServicePayloadKind> {
match self {
Service::Clock(_) => service_datetime::ClockTicker::run(),
}
}
}