1use std::path::Path;
2
3use abi_stable::{
4 library::{lib_header_from_path, LibraryError, RootModule},
5 package_version_strings,
6 sabi_types::VersionStrings,
7 std_types::{RString, RVec},
8 StableAbi,
9};
10use async_ffi::BorrowingFfiFuture;
11
12use crate::registry::Registry;
13
14#[repr(C)]
15#[derive(StableAbi)]
16#[sabi(kind(Prefix(prefix_ref = PluginApiRef)))]
17#[sabi(missing_field(panic))]
18pub struct PluginApi {
19 #[sabi(last_prefix_field)]
20 pub call: for<'fut> extern "C" fn(
21 RString,
22 &'fut Registry,
23 RVec<u8>,
24 ) -> BorrowingFfiFuture<'fut, RVec<u8>>,
25}
26
27impl RootModule for PluginApiRef {
29 abi_stable::declare_root_module_statics! {PluginApiRef}
30
31 const BASE_NAME: &'static str = "plugin";
32 const NAME: &'static str = "plugin";
33 const VERSION_STRINGS: VersionStrings = package_version_strings!();
34}
35
36pub fn load_plugin(path: &Path) -> Result<PluginApiRef, LibraryError> {
37 lib_header_from_path(path).and_then(|x| x.init_root_module::<PluginApiRef>())
38}