| Crates.io | plugin-interfaces |
| lib.rs | plugin-interfaces |
| version | 0.1.2 |
| created_at | 2025-06-06 05:56:32.27638+00 |
| updated_at | 2025-06-11 05:21:32.295415+00 |
| description | Plugin interfaces for chat-client application |
| homepage | |
| repository | https://github.com/luodeb/plugin-interfaces.git |
| max_upload_size | |
| id | 1702622 |
| size | 86,720 |
A comprehensive Rust crate that provides the core interface definitions and abstractions for the chat-client plugin system. This crate serves as the foundation for building dynamic, loadable plugins that can extend the functionality of the chat-client application.
The plugin-interfaces crate defines a standardized plugin architecture that enables:
handler.rs)The main trait that all plugins must implement:
pub trait PluginHandler {
fn init_ui(&mut self, ctx: &CreationContext, ui: &mut Ui);
fn update_ui(&mut self, ctx: &Context, ui: &mut Ui);
fn on_mount(&mut self, metadata: &PluginMetadata) -> Result<(), Box<dyn std::error::Error>>;
fn on_dispose(&mut self) -> Result<(), Box<dyn std::error::Error>>;
fn on_connect(&mut self) -> Result<(), Box<dyn std::error::Error>>;
fn on_disconnect(&mut self) -> Result<(), Box<dyn std::error::Error>>;
fn handle_message(&self, message: &str) -> Result<String, Box<dyn std::error::Error>>;
fn get_metadata(&self) -> PluginMetadata;
}
symbols.rs)Provides C-compatible function pointers for cross-language plugin loading:
PluginInterface: FFI-safe struct containing function pointersCreatePluginFn / DestroyPluginFn: Plugin lifecycle managementcreate_plugin and destroy_pluginpluginui/)An immediate-mode UI framework that provides:
message/)Comprehensive messaging infrastructure:
callbacks.rs)Interface for plugins to communicate with the host application:
send_to_frontend: Send messages to the frontendget_app_config: Access application configurationcall_other_plugin: Inter-plugin communicationconfig.rs)Plugin configuration management:
metadata.rs)Plugin metadata structures:
PluginMetadata: Rust-native metadata structurePluginMetadataFFI: FFI-safe metadata for cross-language compatibilitylogging/)Structured logging system for plugins with different log levels and formatting.
api.rs)High-level API functions for common plugin operations:
send_to_frontend: Simplified frontend communicationhost_send_to_frontend: Direct host communicationcreate_plugininitializeinit_ui called to set up initial user interfaceon_mount called with plugin metadataupdate_ui called for UI updates and event handlinghandle_message processes incoming messageson_connect/on_disconnect handle connection state changeson_dispose and destroy called during shutdownuse plugin_interface::*;
struct MyPlugin {
name: String,
// ... other fields
}
impl PluginHandler for MyPlugin {
fn init_ui(&mut self, ctx: &CreationContext, ui: &mut Ui) {
ui.text_edit_singleline(&mut self.name);
ui.button("Click me");
}
fn update_ui(&mut self, ctx: &Context, ui: &mut Ui) {
if ui.button("Click me").clicked() {
self.send_message_to_frontend("Button clicked!");
}
}
// ... implement other required methods
}
// Export plugin creation function
#[no_mangle]
pub extern "C" fn create_plugin() -> *mut PluginInterface {
let plugin = Box::new(MyPlugin { name: String::new() });
create_plugin_interface(plugin)
}
serde: Serialization/deserializationserde_json: JSON support for message passinguuid: Unique identifier generationtoml: Configuration file parsingThis crate is designed to be used by:
PluginHandler trait to create new pluginsThe plugin system supports both Rust-native plugins and plugins written in other languages that can export C-compatible functions.