use std::collections::HashMap;
use super::component_api::ComponentApi;
use super::function_api::FunctionImplementation;
pub struct Catalog {
pub id: String,
pub components: HashMap<String, Box<dyn ComponentApi>>,
pub functions: HashMap<String, Box<dyn FunctionImplementation>>,
}
impl Catalog {
pub fn new(id: impl Into<String>) -> Self {
Self {
id: id.into(),
components: HashMap::new(),
functions: HashMap::new(),
}
}
pub fn with_component(mut self, component: Box<dyn ComponentApi>) -> Self {
self.components.insert(component.name().to_string(), component);
self
}
pub fn with_function(mut self, function: Box<dyn FunctionImplementation>) -> Self {
self.functions.insert(function.name().to_string(), function);
self
}
pub fn get_component(&self, name: &str) -> Option<&dyn ComponentApi> {
self.components.get(name).map(|b| b.as_ref())
}
pub fn get_function(&self, name: &str) -> Option<&dyn FunctionImplementation> {
self.functions.get(name).map(|b| b.as_ref())
}
}