reactive_graph_plugin_api/
plugin_dependency.rs1use crate::PLUGIN_NAME_PREFIX;
2
3#[derive(Copy, Clone, PartialEq, Eq, Hash)]
4pub struct PluginDependency {
5 pub name: &'static str,
7
8 pub version: &'static str,
10}
11
12impl PluginDependency {
13 pub fn new(name: &'static str, version: &'static str) -> Self {
14 PluginDependency { name, version }
15 }
16
17 pub fn name_canonicalized(&self) -> String {
18 self.name.replace(PLUGIN_NAME_PREFIX, "")
19 }
20
21 pub fn name_version(&self) -> String {
22 format!("{}:{}", self.name_canonicalized(), self.version)
23 }
24}
25
26#[macro_export]
27macro_rules! plugin_dependencies {
28 () => {
29 #[allow(improper_ctypes_definitions)]
30 extern "C" fn get_dependencies() -> std::vec::Vec<$crate::PluginDependency> {
31 std::vec::Vec::new()
32 }
33 };
34
35 (
36 "dependencies": [
37 $({
38 "name": $plugin_name: expr,
39 "version": $version_range: expr$(,)?
40 }$(,)?)*
41 ]$(,)?
42 ) => {
43 #[allow(improper_ctypes_definitions)]
44 extern "C" fn get_dependencies() -> std::vec::Vec<$crate::PluginDependency> {
45 vec![
46 $($crate::PluginDependency::new($plugin_name, $version_range),)*
47 ]
48 }
49 };
50}