pub trait Plugin: Send + Sync {
// Required method
fn name(&self) -> &str;
// Provided methods
fn version(&self) -> &str { ... }
fn dependencies(&self) -> Vec<&str> { ... }
fn init_sql(&self) -> Vec<String> { ... }
fn migration_sql(&self) -> Vec<(String, String)> { ... }
fn config_schema(&self) -> Option<JsonValue> { ... }
fn on_register<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn on_init<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn on_shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
插件接口
所有插件必须实现此 trait
§示例
ⓘ
use yang_base::plugin::Plugin;
use async_trait::async_trait;
struct MyPlugin;
#[async_trait]
impl Plugin for MyPlugin {
fn name(&self) -> &str {
"my_plugin"
}
fn version(&self) -> &str {
"1.0.0"
}
fn init_sql(&self) -> Vec<String> {
vec![
"CREATE TABLE IF NOT EXISTS my_table (id INT PRIMARY KEY)".to_string()
]
}
}