1use abi_stable::{
2 declare_root_module_statics,
3 library::RootModule,
4 package_version_strings,
5 sabi_types::VersionStrings,
6 std_types::{ROption, RString, RVec},
7 StableAbi,
8};
9
10#[repr(C)]
11#[derive(StableAbi)]
12#[sabi(kind(Prefix(prefix_ref = PluginRef)))]
13#[sabi(missing_field(panic))]
14pub struct Plugin {
15 pub init: extern "C" fn(RString),
16 pub info: extern "C" fn() -> PluginInfo,
17 pub get_matches: extern "C" fn(RString) -> u64,
18 pub poll_matches: extern "C" fn(u64) -> PollResult,
19 pub handle_selection: extern "C" fn(Match) -> HandleResult,
20}
21
22#[repr(C)]
24#[derive(StableAbi, Debug)]
25pub struct PluginInfo {
26 pub name: RString,
27 pub icon: RString,
29}
30
31#[repr(C)]
36#[derive(StableAbi, Clone)]
37pub struct Match {
38 pub title: RString,
39 pub description: ROption<RString>,
40 pub use_pango: bool,
42 pub icon: ROption<RString>,
44 pub id: ROption<u64>,
46}
47
48#[repr(C)]
50#[derive(StableAbi)]
51pub enum HandleResult {
52 Close,
54 Refresh(bool),
57 Copy(RVec<u8>),
59 Stdout(RVec<u8>),
61}
62
63#[repr(C)]
64#[derive(StableAbi)]
65pub enum PollResult {
66 Ready(RVec<Match>),
67 Pending,
68 Cancelled,
69}
70
71impl RootModule for PluginRef {
72 declare_root_module_statics! {PluginRef}
73
74 const BASE_NAME: &'static str = "anyrun_plugin";
75 const NAME: &'static str = "anyrun_plugin";
76 const VERSION_STRINGS: VersionStrings = package_version_strings!();
77}