use async_trait::async_trait;
use serde_json::Value as JsonValue;
use std::fmt;
pub type PluginError = Box<dyn std::error::Error + Send + Sync + 'static>;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum PluginLifecycleStage {
Register,
Initialize,
Shutdown,
}
impl fmt::Display for PluginLifecycleStage {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(match self {
Self::Register => "register",
Self::Initialize => "initialize",
Self::Shutdown => "shutdown",
})
}
}
#[async_trait]
pub trait Plugin: Send + Sync {
fn name(&self) -> &str;
fn version(&self) -> &str {
"0.1.0"
}
fn dependencies(&self) -> &[&str] {
&[]
}
fn config_schema(&self) -> Option<JsonValue> {
None
}
async fn on_register(&self) -> Result<(), PluginError> {
Ok(())
}
async fn on_init(&self) -> Result<(), PluginError> {
Ok(())
}
async fn on_shutdown(&self) -> Result<(), PluginError> {
Ok(())
}
}