fusabi_plugin_runtime/lib.rs
1//! # fusabi-plugin-runtime
2//!
3//! Plugin loader, hot-reload, and runtime for Fusabi plugins (fsx & fzb)
4//! with manifest validation and capability enforcement.
5//!
6//! This crate provides:
7//! - **Plugin Loading** - Load plugins from source (.fsx) or bytecode (.fzb)
8//! - **Manifest Validation** - Validate plugin manifests and enforce requirements
9//! - **Capability Enforcement** - Ensure plugins only use declared capabilities
10//! - **Hot Reload** - Automatically reload plugins when files change
11//! - **Lifecycle Management** - Initialize, run, and cleanup plugins
12//! - **Metrics Hooks** - Track plugin performance and usage
13//!
14//! ## Quick Start
15//!
16//! ```rust,ignore
17//! use fusabi_plugin_runtime::{PluginLoader, LoaderConfig, PluginRegistry};
18//!
19//! // Create a loader
20//! let loader = PluginLoader::new(LoaderConfig::default())?;
21//!
22//! // Load a plugin from manifest
23//! let plugin = loader.load_from_manifest("plugin.toml")?;
24//!
25//! // Call plugin functions
26//! let result = plugin.call("main", &[])?;
27//! ```
28//!
29//! ## Feature Flags
30//!
31//! - `serde` (default): Enable manifest parsing and serialization
32//! - `watch`: Enable filesystem watching for hot reload
33//! - `metrics-prometheus`: Prometheus metrics integration
34
35#![warn(missing_docs)]
36#![warn(rust_2018_idioms)]
37
38mod error;
39mod lifecycle;
40mod loader;
41mod manifest;
42mod plugin;
43mod registry;
44mod runtime;
45
46#[cfg(feature = "watch")]
47mod watcher;
48
49#[cfg(feature = "metrics-prometheus")]
50mod metrics;
51
52pub use error::{Error, Result};
53pub use lifecycle::{PluginLifecycle, LifecycleState, LifecycleHooks};
54pub use loader::{PluginLoader, LoaderConfig};
55pub use manifest::{Manifest, ManifestBuilder, ApiVersion, Dependency};
56pub use plugin::{Plugin, PluginInfo, PluginHandle};
57pub use registry::{PluginRegistry, RegistryConfig};
58pub use runtime::{PluginRuntime, RuntimeConfig};
59
60#[cfg(feature = "watch")]
61pub use watcher::{PluginWatcher, WatchConfig, WatchEvent};
62
63#[cfg(feature = "metrics-prometheus")]
64pub use metrics::{PluginMetrics, MetricsConfig};
65
66// Re-export key types from fusabi-host for convenience
67pub use fusabi_host::{
68 Capabilities, Capability, Limits, Value, Error as HostError,
69};
70
71/// Crate version for compatibility checks.
72pub const VERSION: &str = env!("CARGO_PKG_VERSION");