reactive_graph_plugin_api/
plugin_declaration.rs

1use std::sync::Arc;
2
3use crate::Plugin;
4use crate::PluginContext;
5use crate::PluginDependency;
6use crate::PluginLoadingError;
7
8#[derive(Copy, Clone)]
9pub struct PluginDeclaration {
10    /// The version of the rust compiler which has compiled the plugin. The version must match with the version the core application has been compiled with.
11    pub rustc_version: &'static str,
12
13    /// The version of plugin API. The version must match with the version of the plugin API used by the core application.
14    pub plugin_api_version: &'static str,
15
16    /// The name of the plugin.
17    pub name: &'static str,
18
19    /// The description of the plugin.
20    pub description: &'static str,
21
22    /// The version of the plugin.
23    pub version: &'static str,
24
25    /// The library registrar function.
26    #[allow(improper_ctypes_definitions)]
27    pub register: unsafe extern "C" fn(&mut dyn PluginRegistrar) -> Result<(), PluginLoadingError>,
28
29    /// Function to get the dependencies of the plugin.
30    #[allow(improper_ctypes_definitions)]
31    pub get_dependencies: unsafe extern "C" fn() -> Vec<PluginDependency>,
32}
33
34/// Contains the registration
35pub trait PluginRegistrar {
36    /// Registers the given plugin with the given name in the core application.
37    fn register_plugin(&mut self, plugin: Box<Arc<dyn Plugin>>);
38
39    /// Returns the plugin context.
40    fn context(&self) -> Arc<dyn PluginContext + Send + Sync>;
41}
42
43#[macro_export]
44macro_rules! export_plugin_declaration {
45    () => {
46        #[doc(hidden)]
47        #[unsafe(no_mangle)]
48        pub static plugin_declaration: $crate::PluginDeclaration = $crate::PluginDeclaration {
49            rustc_version: $crate::RUSTC_VERSION,
50            plugin_api_version: $crate::PLUGIN_API_VERSION,
51            name: PLUGIN_NAME,
52            description: PLUGIN_DESCRIPTION,
53            version: PLUGIN_VERSION,
54            register,
55            get_dependencies,
56        };
57    };
58}