pub enum CommandResult {
Ok,
Error(String),
}
pub trait PluginContext {
fn register_command(&mut self, name: &str, handler: fn(args: &[String]) -> CommandResult);
fn register_build_step(&mut self, name: &str, handler: fn() -> anyhow::Result<()>);
fn register_asset_processor(
&mut self,
extension: &str,
handler: fn(path: &std::path::Path) -> anyhow::Result<()>,
);
}
pub trait Plugin: Send + Sync {
fn name(&self) -> &str;
fn register(&self, ctx: &mut dyn PluginContext);
fn shutdown(&self) {}
}
pub struct PluginRegistry {
plugins: Vec<Box<dyn Plugin>>,
}
impl PluginRegistry {
pub fn new() -> Self {
Self {
plugins: Vec::new(),
}
}
pub fn register<P: Plugin + 'static>(&mut self, plugin: P) {
log::info!("Registering plugin: {}", plugin.name());
self.plugins.push(Box::new(plugin));
}
pub fn len(&self) -> usize {
self.plugins.len()
}
pub fn is_empty(&self) -> bool {
self.plugins.is_empty()
}
}
impl Default for PluginRegistry {
fn default() -> Self {
Self::new()
}
}