DEV Community

Cover image for 🚀 Turbocharge Your Rust Project with plugins using plugy!
Njuguna Mureithi
Njuguna Mureithi

Posted on

🚀 Turbocharge Your Rust Project with plugins using plugy!

Get ready to supercharge your Rust projects with plugy, the dynamic and playful plugin system that seamlessly integrates Rust-based plugins into your application. By providing a runtime environment for loading and executing WebAssembly (Wasm) plugins, plugy brings a new level of excitement and flexibility to your Rust development journey.

Features that Spark Joy in Your Rust Projects

  • Load and Execute Wasm Plugins: plugy lets you load and execute plugins compiled to WebAssembly, turning your Rust applications into dynamic powerhouses!

  • Flexible Runtime Management: Enjoy the freedom of flexible runtime management for your plugins, bringing dynamic extensibility without breaking a sweat.

  • Async Plugin Function Calls: plugy supports asynchronous plugin function calls, ensuring a smooth and entertaining integration of plugins into your async Rust applications.

  • Easy-to-Use Macros: Simplify the generation of plugin interfaces with plugy's snazzy macros, making the process of working with dynamic plugins as fun as a game.

🎮 Let the plugy Adventure Begin!

1. Define Your Plugin Trait

#[plugy::plugin]
trait Greeter {
    fn greet(&self) -> String;
}
Enter fullscreen mode Exit fullscreen mode

2. Implement Your First Plugin

#[derive(Debug, Deserialize)]
struct FooPlugin;

#[plugin_impl]
impl Greeter for FooPlugin {
    fn greet(&self) -> String {
        "Hello From Foo Plugin".to_owned()
    }
}
Enter fullscreen mode Exit fullscreen mode

Compile your plugin:

cargo build --target wasm32-unknown-unknown
Enter fullscreen mode Exit fullscreen mode

3. Import and Run

#[plugin_import(file = "target/wasm32-unknown-unknown/debug/foo_plugin.wasm")]
struct FooPlugin;

#[tokio::main]
async fn main() {
    let runtime = Runtime::<Box<dyn Greeter>>::new().unwrap();
    let handle = runtime.load(FooPlugin).await.unwrap();
    let res = handle.greet().await;
    assert_eq!(res, "Hello From Foo Plugin")
}
Enter fullscreen mode Exit fullscreen mode

And just like that, you're all set to embark on a dynamic extensibility adventure in your Rust project!

🚀 Examples for Practical Application

Explore the examples directory to find a thrilling use case that showcase the power and versatility of plugy in action.

🔓 Unlocking Functionality with plugy

plugy comprises three essential crates, each playing a distinct role in crafting dynamic plugin systems with Rust and WebAssembly:

  • core: This crate provides foundational components such as bitwise utilities and the guest module, forming the basis of plugy's functionality.

  • runtime: Orchestrating the execution of your plugin system, the runtime crate seamlessly integrates plugins into your applications, offering a smooth and efficient experience.

  • macros: The macros crate offers a collection of macros that simplify the generation of bindings and interfaces, making it easier to work with dynamic plugins.

🎉 Conclusion

With plugy, you're not just coding; you're on a journey of dynamic extensibility, unlocking new possibilities and embracing the flexibility that plugy brings to your Rust development. Happy coding and have a blast! 🚀✨

Github

https://github.com/geofmureithi/plugy

Top comments (0)