mangofetch_plugin_sdk/
plugin.rs1use std::sync::Arc;
2
3use crate::host::PluginHost;
4
5pub trait MangoFetchPlugin: Send + Sync {
6 fn id(&self) -> &str;
7 fn name(&self) -> &str;
8 fn version(&self) -> &str;
9 fn initialize(&mut self, host: Arc<dyn PluginHost>) -> anyhow::Result<()>;
10 fn shutdown(&self) {}
11
12 fn handle_command(
13 &self,
14 command: String,
15 args: serde_json::Value,
16 ) -> std::pin::Pin<
17 Box<dyn std::future::Future<Output = Result<serde_json::Value, String>> + Send + 'static>,
18 >;
19
20 fn commands(&self) -> Vec<String>;
21}
22
23#[macro_export]
24macro_rules! export_plugin {
25 ($constructor:expr) => {
26 #[no_mangle]
27 pub extern "C" fn mangofetch_plugin_abi_version() -> u32 {
28 $crate::ABI_VERSION
29 }
30
31 #[no_mangle]
32 pub extern "C" fn mangofetch_plugin_init() -> *mut dyn $crate::MangoFetchPlugin {
33 let plugin = $constructor;
34 Box::into_raw(Box::new(plugin))
35 }
36 };
37}