folk-api 0.1.1

Plugin contract for the Folk PHP application server
Documentation
//! Plugin factory: how `folk-builder`'s generated `main.rs` constructs each plugin.
//!
//! The convention is: every plugin crate exports
//!
//! ```rust,ignore
//! pub fn folk_plugin_factory() -> Box<dyn folk_api::PluginFactory> {
//!     Box::new(MyPluginFactory)
//! }
//! ```
//!
//! The builder calls `crate_name::folk_plugin_factory()` for each plugin
//! and registers the result. There is no other naming convention; the
//! function name is fixed.

use anyhow::Result;
use serde_json::Value as JsonValue;

use crate::plugin::Plugin;

/// Constructs a [`Plugin`] from runtime configuration.
pub trait PluginFactory: Send + Sync + 'static {
    /// Construct a plugin from its config section (JSON from `folk.toml`).
    fn create(&self, config: JsonValue) -> Result<Box<dyn Plugin>>;
}