pipedash_plugin_api/
registry.rs

1use std::collections::HashMap;
2
3use crate::plugin::Plugin;
4
5pub struct PluginRegistry {
6    plugins: HashMap<String, Box<dyn Plugin>>,
7}
8
9impl PluginRegistry {
10    pub fn new() -> Self {
11        Self {
12            plugins: HashMap::new(),
13        }
14    }
15
16    pub fn register(&mut self, plugin: Box<dyn Plugin>) {
17        let provider_type = plugin.provider_type().to_string();
18        self.plugins.insert(provider_type, plugin);
19    }
20
21    pub fn get(&self, provider_type: &str) -> Option<&dyn Plugin> {
22        self.plugins.get(provider_type).map(|p| p.as_ref())
23    }
24
25    pub fn is_registered(&self, provider_type: &str) -> bool {
26        self.plugins.contains_key(provider_type)
27    }
28
29    pub fn provider_types(&self) -> Vec<String> {
30        self.plugins.keys().cloned().collect()
31    }
32
33    pub fn count(&self) -> usize {
34        self.plugins.len()
35    }
36}
37
38impl Default for PluginRegistry {
39    fn default() -> Self {
40        Self::new()
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_registry_creation() {
50        let registry = PluginRegistry::new();
51        assert_eq!(registry.count(), 0);
52    }
53}