use std::collections::HashMap;
pub trait Feature {
fn execute(&self) -> Result<(), String>;
}
pub struct FeatureManager {
features: HashMap<&'static str, Box<dyn Feature>>,
}
impl FeatureManager {
pub fn new() -> Self {
Self {
features: HashMap::new(),
}
}
pub fn register_feature<F: Feature + 'static>(&mut self, name: &'static str, feature: F) {
self.features.insert(name, Box::new(feature));
}
pub fn execute_feature(&self, name: &'static str) -> Result<(), String> {
if let Some(feature) = self.features.get(name) {
feature.execute()
} else {
Err(format!("Feature '{}' not found", name))
}
}
}