Skip to main content

rustbridge_consumer/
lib.rs

1//! Rust consumer for rustbridge plugins.
2//!
3//! This crate enables Rust applications to dynamically load and invoke rustbridge
4//! plugin bundles (`.rbp` files) or shared libraries at runtime. It provides the
5//! same functionality available to Java, Kotlin, C#, and Python consumers.
6//!
7//! # Features
8//!
9//! - **Dynamic Loading**: Load plugins at runtime without compile-time linking
10//! - **Bundle Support**: Load from `.rbp` bundles with automatic platform detection
11//! - **Signature Verification**: Verify minisign signatures on bundles
12//! - **JSON Transport**: Make calls using JSON serialization
13//! - **Binary Transport**: High-performance binary struct transport (7x faster)
14//! - **Lifecycle Management**: Full OSGI-inspired lifecycle state machine
15//! - **Logging Integration**: Route plugin logs through host callbacks
16//!
17//! # Quick Start
18//!
19//! ```ignore
20//! use rustbridge_consumer::{NativePluginLoader, ConsumerResult};
21//!
22//! fn main() -> ConsumerResult<()> {
23//!     // Load a plugin
24//!     let plugin = NativePluginLoader::load("target/release/libmy_plugin.so")?;
25//!
26//!     // Make a call
27//!     let response = plugin.call("echo", r#"{"message": "Hello"}"#)?;
28//!     println!("Response: {response}");
29//!
30//!     Ok(())
31//! }
32//! ```
33//!
34//! # Loading from Bundles
35//!
36//! ```ignore
37//! use rustbridge_consumer::{NativePluginLoader, PluginConfig};
38//!
39//! let config = PluginConfig::default();
40//! let plugin = NativePluginLoader::load_bundle_with_config(
41//!     "my-plugin-1.0.0.rbp",
42//!     &config,
43//!     None,
44//! )?;
45//! ```
46//!
47//! # Loading with Signature Verification
48//!
49//! ```ignore
50//! use rustbridge_consumer::{NativePluginLoader, PluginConfig};
51//!
52//! // Load with signature verification (recommended for production)
53//! let plugin = NativePluginLoader::load_bundle_with_verification(
54//!     "my-plugin-1.0.0.rbp",
55//!     &PluginConfig::default(),
56//!     None,   // no log callback
57//!     true,   // verify signatures
58//!     None,   // use manifest's public key
59//! )?;
60//! ```
61//!
62//! # Typed Calls
63//!
64//! ```ignore
65//! use serde::{Serialize, Deserialize};
66//!
67//! #[derive(Serialize)]
68//! struct EchoRequest { message: String }
69//!
70//! #[derive(Deserialize)]
71//! struct EchoResponse { message: String, length: usize }
72//!
73//! let response: EchoResponse = plugin.call_typed("echo", &EchoRequest {
74//!     message: "Hello".to_string(),
75//! })?;
76//! ```
77
78mod error;
79mod ffi_bindings;
80mod loader;
81mod plugin;
82
83pub use error::{ConsumerError, ConsumerResult};
84pub use loader::{LogCallbackFn, NativePluginLoader};
85pub use plugin::NativePlugin;
86
87// Re-export commonly used types from dependencies
88pub use rustbridge_core::{LifecycleState, LogLevel, PluginConfig, PluginError};
89
90/// Prelude module for convenient imports.
91pub mod prelude {
92    pub use crate::{
93        ConsumerError, ConsumerResult, LifecycleState, LogCallbackFn, LogLevel, NativePlugin,
94        NativePluginLoader, PluginConfig,
95    };
96}