2020-01-21 04:10:40 +00:00
|
|
|
use crate::app::AppBuilder;
|
|
|
|
use libloading::{Library, Symbol};
|
|
|
|
use std::any::Any;
|
|
|
|
|
|
|
|
pub trait AppPlugin: Any + Send + Sync {
|
2020-03-22 10:06:08 +00:00
|
|
|
fn build(&self, app_builder: &mut AppBuilder) -> &mut AppBuilder;
|
2020-01-21 04:10:40 +00:00
|
|
|
fn name(&self) -> &'static str;
|
|
|
|
}
|
|
|
|
|
|
|
|
type CreateAppPlugin = unsafe fn() -> *mut dyn AppPlugin;
|
|
|
|
|
|
|
|
pub fn load_plugin(path: &str) -> (Library, Box<dyn AppPlugin>) {
|
|
|
|
let lib = Library::new(path).unwrap();
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let func: Symbol<CreateAppPlugin> = lib.get(b"_create_plugin").unwrap();
|
|
|
|
let plugin = Box::from_raw(func());
|
|
|
|
(lib, plugin)
|
|
|
|
}
|
2020-02-08 07:17:51 +00:00
|
|
|
}
|