| Crates.io | steckrs |
| lib.rs | steckrs |
| version | 0.4.0 |
| created_at | 2025-03-10 13:08:21.074774+00 |
| updated_at | 2025-03-19 16:25:59.944199+00 |
| description | A lightweight, trait-based plugin system for Rust applications and libraries |
| homepage | https://github.com/PlexSheep/steckrs |
| repository | https://github.com/PlexSheep/steckrs |
| max_upload_size | |
| id | 1586608 |
| size | 125,925 |
A lightweight, trait-based plugin system for Rust applications. The name "steckrs" is a wordplay combining the German word "Stecker" (meaning "plug" or "connector") and the Rust file extension (.rs).
# in your rust/cargo project
cargo add steckrs
git clone https://github.com/PlexSheep/steckrs.git
cd steckrs
cargo build --release
ls ./target/release/libsteckrs.rlib # here is the rlib if you want that
Here's a simple example of how to use steckrs to create a plugin-enabled application:
use steckrs::{extension_point, simple_plugin, PluginManager};
// Define an extension point with documentation
extension_point!(
GreeterExtension:
GreeterTrait;
/// foo
fn greet(&self, name: &str) -> String;
);
// Implement a hook
/// English implementation of the greeter
struct EnglishGreeter;
impl GreeterTrait for EnglishGreeter {
fn greet(&self, name: &str) -> String {
format!("Hello, {}!", name)
}
}
// Create a plugin with documentation
simple_plugin!(
/// A Plugin providing English greeting functionality
HelloPlugin,
"hello_plugin",
"A simple greeting plugin",
hooks: [(GreeterExtension, EnglishGreeter)]
);
fn main() {
// Create plugin manager
let mut plugin_manager = PluginManager::new();
// Load and enable the plugin
plugin_manager
.load_plugin(Box::new(HelloPlugin::new()))
.unwrap();
plugin_manager.enable_plugin(HelloPlugin::ID).unwrap();
// Get all enabled hooks (plugins could be disabled)
let hooks = plugin_manager.get_enabled_hooks_by_ep::<GreeterExtension>();
// Execute all hooks relevant for this extension point
for (_id, hook) in hooks {
println!("{}", hook.inner().greet("World"));
}
}
Extension points define interfaces where plugins can add functionality. Each extension point:
Plugins are self-contained data structures that implement functionality for extension points. Each plugin:
on_load, on_unload)Hooks are implementations of extension points that plugins register. They:
steckrs provides several convenience macros to reduce boilerplate:
extension_point! - Defines an extension point and its associated traitsimple_plugin! - Creates a simple plugin with minimal boilerplateregister_hook! - Registers a hook with the hook registryFor more complex scenarios, you can implement the Plugin trait directly, allowing for more customized plugin behavior and state management. A good starting point would be defining a plugin with simple_plugin! and then expanding the macro.
dyn then.Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)Distributed under the LGPL License. See LICENSE for more information.