1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
pub static CORE_VERSION: &str = env!("CARGO_PKG_VERSION");
pub static RUSTC_VERSION: &str = env!("RUSTC_VERSION");
pub trait AutoclipPlugin {
fn on_clip(&self, contents: &str) -> Option<String>;
}
pub struct PluginDeclaration {
pub rustc_version: &'static str,
pub core_version: &'static str,
pub register: unsafe extern "C" fn(&mut dyn PluginRegistrar),
}
pub trait PluginRegistrar {
fn register(&mut self, name: &str, entrypoint: Box<dyn AutoclipPlugin>);
}
#[macro_export]
macro_rules! export_plugin {
($name:expr, $implementation:expr) => {
#[doc(hidden)]
#[no_mangle]
pub static plugin_declaration: $crate::PluginDeclaration = $crate::PluginDeclaration {
rustc_version: $crate::RUSTC_VERSION,
core_version: $crate::CORE_VERSION,
register,
};
#[allow(improper_ctypes_definitions)]
extern "C" fn register(registrar: &mut dyn PluginRegistrar) {
registrar.register($name, Box::new($implementation));
}
};
}