-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathlib.rs
50 lines (42 loc) · 1.28 KB
/
lib.rs
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
pub mod config;
use std::path::PathBuf;
use std::sync::Arc;
use async_trait::async_trait;
use http::request::Parts;
use http_body_util::Full;
use hyper::body::Bytes;
use hyper::Response;
use tokio::runtime::Handle;
pub static CORE_VERSION: &str = env!("CARGO_PKG_VERSION");
pub static RUSTC_VERSION: &str = env!("RUSTC_VERSION");
#[async_trait]
pub trait Plugin: Send + Sync {
async fn call(&self, parts: Parts, body: Bytes) -> Result<Response<Full<Bytes>>, PluginError>;
}
#[derive(Debug)]
pub enum PluginError {
SpawnError { err: String },
Other { msg: String },
}
#[allow(improper_ctypes_definitions)]
pub struct PluginDeclaration {
pub rustc_version: &'static str,
pub core_version: &'static str,
pub register:
unsafe extern "C" fn(config_path: PathBuf, rt: Arc<Handle>, &mut dyn PluginRegistrar),
}
pub trait PluginRegistrar {
fn register_function(&mut self, name: &str, function: Arc<dyn Plugin>);
}
#[macro_export]
macro_rules! export_plugin {
($register:expr) => {
#[doc(hidden)]
#[no_mangle]
pub static PLUGIN_DECLARATION: $crate::PluginDeclaration = $crate::PluginDeclaration {
rustc_version: $crate::RUSTC_VERSION,
core_version: $crate::CORE_VERSION,
register: $register,
};
};
}