use super::Extension;
use std::collections::HashMap;
use std::sync::Arc;
pub struct ExtensionRegistry {
extensions: HashMap<String, Arc<dyn Extension>>,
}
impl ExtensionRegistry {
pub fn new() -> Self {
Self {
extensions: HashMap::new(),
}
}
#[allow(dead_code)]
pub fn register_type(&mut self, extension: Arc<dyn Extension>) {
let extension_type = extension.extension_type().to_string();
self.extensions.insert(extension_type, extension);
}
pub fn get(&self, extension_type: &str) -> Option<Arc<dyn Extension>> {
self.extensions.get(extension_type).cloned()
}
#[allow(dead_code)]
pub fn list(&self) -> Vec<String> {
self.extensions.keys().cloned().collect()
}
pub fn iter(&self) -> impl Iterator<Item = (&String, &Arc<dyn Extension>)> {
self.extensions.iter()
}
}
impl Default for ExtensionRegistry {
fn default() -> Self {
Self::new()
}
}