pub trait Plugin: Send + Sync {
// Required method
fn name(&self) -> &str;
// Provided methods
fn version(&self) -> &str { ... }
fn dependencies(&self) -> &[&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<(), PluginError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn on_init<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn on_shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + 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()
]
}
}Required Methods§
Provided Methods§
Sourcefn dependencies(&self) -> &[&str]
fn dependencies(&self) -> &[&str]
Sourcefn migration_sql(&self) -> Vec<(String, String)>
fn migration_sql(&self) -> Vec<(String, String)>
Sourcefn config_schema(&self) -> Option<JsonValue>
fn config_schema(&self) -> Option<JsonValue>
Sourcefn on_register<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_register<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sourcefn on_init<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_init<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sourcefn on_shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".