Skip to main content

folk_api/
factory.rs

1//! Plugin factory: how `folk-builder`'s generated `main.rs` constructs each plugin.
2//!
3//! The convention is: every plugin crate exports
4//!
5//! ```rust,ignore
6//! pub fn folk_plugin_factory() -> Box<dyn folk_api::PluginFactory> {
7//!     Box::new(MyPluginFactory)
8//! }
9//! ```
10//!
11//! The builder calls `crate_name::folk_plugin_factory()` for each plugin
12//! and registers the result. There is no other naming convention; the
13//! function name is fixed.
14
15use anyhow::Result;
16use serde_json::Value as JsonValue;
17
18use crate::plugin::Plugin;
19
20/// Constructs a [`Plugin`] from runtime configuration.
21pub trait PluginFactory: Send + Sync + 'static {
22    /// Construct a plugin from its config section (JSON from `folk.toml`).
23    fn create(&self, config: JsonValue) -> Result<Box<dyn Plugin>>;
24}