Skip to main content

minion_engine/plugins/
registry.rs

1use std::collections::HashMap;
2
3use super::PluginStep;
4
5/// Registry that stores and retrieves plugins by name
6pub struct PluginRegistry {
7    plugins: HashMap<String, Box<dyn PluginStep>>,
8}
9
10impl PluginRegistry {
11    pub fn new() -> Self {
12        Self {
13            plugins: HashMap::new(),
14        }
15    }
16
17    /// Register a plugin. If a plugin with the same name already exists, it is replaced.
18    pub fn register(&mut self, plugin: Box<dyn PluginStep>) {
19        let name = plugin.name().to_string();
20        self.plugins.insert(name, plugin);
21    }
22
23    /// Look up a plugin by name
24    pub fn get(&self, name: &str) -> Option<&Box<dyn PluginStep>> {
25        self.plugins.get(name)
26    }
27
28    /// Return the number of registered plugins
29    pub fn len(&self) -> usize {
30        self.plugins.len()
31    }
32
33    /// Return true if no plugins are registered
34    pub fn is_empty(&self) -> bool {
35        self.plugins.is_empty()
36    }
37}
38
39impl Default for PluginRegistry {
40    fn default() -> Self {
41        Self::new()
42    }
43}