Skip to main content

photon_backend/
handler_registry.rs

1//! Registry of `#[photon::subscribe]` handlers discovered via inventory.
2
3#![allow(missing_docs)]
4
5use crate::handler_descriptor::HandlerDescriptor;
6
7quark::define_registry! {
8    /// Registry of inventory-submitted subscription handlers.
9    pub struct HandlerRegistry for HandlerDescriptor;
10}
11
12impl HandlerRegistry {
13    /// Handlers for a topic in stable registry-key order.
14    #[must_use]
15    pub fn for_topic(&self, topic_name: &str) -> Vec<&'static HandlerDescriptor> {
16        let mut handlers: Vec<&'static HandlerDescriptor> = self
17            .iter()
18            .filter(|h| h.topic_name == topic_name)
19            .collect();
20        handlers.sort_by_key(|h| h.registry_key);
21        handlers
22    }
23}