Crate dygpi[−][src]
Expand description
Provides support for Dynamic Generic PlugIns, library based plugins for Rust.
This crate implements a simple plugin model that allows for loading of implementations from external dynamic libraries at runtime.
- The plugin host defines a concrete type, the plugin type.
- The plugin type MUST implement the trait
Plugin
. - It MAY be preferable to define the plugin type in a separate plugin API crate that both the host and provider depend upon.
- The plugin type MUST implement the trait
- The plugin provider (or library) crate MUST set crate-type to
"dylib"
and"rlib"
in their cargo configuration. - The plugin provider MUST implement a function, named
register_plugins
, which is passed a registrar object to register any instances of the plugin type.- A plugin provider can use an alternate name for the registration function but this must be
provided to the plugin manager via the
set_registration_fn_name
method.
- A plugin provider can use an alternate name for the registration function but this must be
provided to the plugin manager via the
- The plugin host then uses the
PluginManager
to load libraries, and register plugins, that have the same type as the plugin type. - The plugin host MAY then use plugin manager’s
get
method to fetch a specific plugin by id, OR use plugin manager’splugins
method to iterate over all plugins.
Overriding the plugin registration function allows a plugin host to provide plugins of different types by using separate registration functions for each type.
Example
The example below shows the plugin manager loading any plugins from a specific library and then retrieving a single plugin by ID from the loaded set.
use dygpi::manager::PluginManager; use dygpi::plugin::Plugin; use std::sync::Arc; fn main() { let mut plugin_manager: PluginManager<SoundEffectPlugin> = PluginManager::default(); plugin_manager .load_plugins_from("libsound_one.dylib".as_ref()) .unwrap(); let plugin: Arc<SoundEffectPlugin> = plugin_manager .get("sound_one::sound_one::DelayEffect") .unwrap(); println!("{}", plugin.plugin_id()); plugin.play(); }
Features
config_serde
: Adds Serde’s Serialize
and Deserialize
traits to the
PluginManagerConfiguration
type so that it can
be used in configuration files.
[plugins] source = ["analog_oscillator", "lfo"] effect = ["delay", "reverb"]
Modules
Provides a configuration type that can be used to map a plugin type identifier to a list of library paths. The result is the ability to create plugin manager instances from this configuration without having to load all the plugin provider paths programmatically.
The components required by a plugin host to load/unload plugins.
The components required to define a plugin API.