pub struct HatRegistry { /* private fields */ }Expand description
Registry for managing and creating hats from configuration.
Implementations§
Source§impl HatRegistry
impl HatRegistry
Sourcepub fn from_config(config: &RalphConfig) -> Self
pub fn from_config(config: &RalphConfig) -> Self
Creates a registry from configuration.
Empty config → empty registry (HatlessRalph is the fallback, not default hats).
Sourcepub fn register_with_config(&mut self, hat: Hat, config: HatConfig)
pub fn register_with_config(&mut self, hat: Hat, config: HatConfig)
Registers a hat with its configuration.
Sourcepub fn get_config(&self, id: &HatId) -> Option<&HatConfig>
pub fn get_config(&self, id: &HatId) -> Option<&HatConfig>
Gets a hat’s configuration by ID.
Sourcepub fn subscribers(&self, topic: &Topic) -> Vec<&Hat>
pub fn subscribers(&self, topic: &Topic) -> Vec<&Hat>
Finds all hats subscribed to a topic. BTreeMap iteration is already sorted by key.
Sourcepub fn find_by_trigger(&self, topic: &str) -> Option<&HatId>
pub fn find_by_trigger(&self, topic: &str) -> Option<&HatId>
Finds the first hat that would be triggered by a topic. Returns the hat ID if found, used for event logging. BTreeMap iteration is already sorted by key.
Sourcepub fn has_subscriber(&self, topic: &str) -> bool
pub fn has_subscriber(&self, topic: &str) -> bool
Returns true if any hat is subscribed to the given topic.
Sourcepub fn can_publish(&self, hat_id: &HatId, topic: &str) -> bool
pub fn can_publish(&self, hat_id: &HatId, topic: &str) -> bool
Check if a hat is allowed to publish the given topic.
Returns true for unregistered hats (Ralph can publish anything).
Uses the same pattern matching as subscription routing.
Sourcepub fn get_for_topic(&self, topic: &str) -> Option<&Hat>
pub fn get_for_topic(&self, topic: &str) -> Option<&Hat>
Returns the first hat subscribed to the given topic.
Uses prefix index for O(1) early-exit when the topic prefix doesn’t match any subscription pattern.