An embeddable plugin system for Rust applications.
- LibPlugin handles the majority of boilerplate required for implementing a functional plugin system; offering some flexibility in design & configuration.
Still under early development; I would recommend against using it for anything serious at the moment.
- Supported Formats:
- Toml
- Ron
- Json
use lp::{PluginManager, Toml};
fn main() {
let toml = Toml::parse("plugin_manifest.toml")
.expect("Failed to parse plugin manifest");
toml.plugin.register(|plugin| {
// custom logic to handle registering the plugin
});
toml.plugin.run(|plugin| {
// custom logic to handle executing the plugin
});
toml.plugin.unregister(|plugin| {
// custom logic to handle unregistering the plugin
});
}
// add to your project: cargo add lp -F dynamic-loading
use lp::{
PluginManager, Toml,
load::{Lib, Loadable, Symbol},
};
fn main() {
let hello_symbol = "hello_fn";
let toml = Toml::parse("plugin.toml").expect("File not found");
toml.plugin.register(|plugin| {
type UnsafeFn = unsafe extern "C" fn() -> *const std::ffi::c_char;
if let Some(path) = &plugin.path {
let hello_lib = unsafe {
Lib::<Symbol<'static, UnsafeFn>>::load(path, hello_symbol)
.expect("Failed to load hello function")
};
if let Some(hello_fn) = &hello_lib.f {
let result = unsafe { hello_fn() };
println!("hello function loaded!");
println!("{}", unsafe {
std::ffi::CStr::from_ptr(result).to_string_lossy()
});
}
}
});
}
- TOML
[plugin]
name = "example"
version = "0.1.0"
authors = ["Author Name"]
description = "An example plugin"
license = "MIT"
path = "/path/to/plugin"
- RON
Ron(
plugin: Plugin(
name: "example",
version: "0.1.0",
authors: Some(["Author Name"]),
description: Some("An example plugin"),
license: Some("MIT"),
path: Some("/path/to/plugin"),
),
)
- JSON
{
"plugin": {
"name": "example",
"version": "0.1.0",
"authors": ["Author Name"],
"description": "An example plugin",
"license": "MIT",
"path": "/path/to/plugin"
}
}
- v1.0.0 API refactor
- v1.1.0 Add opt-in support for MCP via rmcp
- Enhance Docs