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.

  1. The plugin host defines a concrete type, the plugin type.
    1. The plugin type MUST implement the trait Plugin.
    2. It MAY be preferable to define the plugin type in a separate plugin API crate that both the host and provider depend upon.
  2. The plugin provider (or library) crate MUST set crate-type to "dylib" and "rlib" in their cargo configuration.
  3. The plugin provider MUST implement a function register_plugins which is passed a registrar object to register any instances of the plugin type.
  4. The plugin host then uses the PluginManager to load libraries, and register plugins, that have the same type as the plugin type.
  5. The plugin host MAY then use plugin manager’s get method to fetch a specific plugin by id, OR use plugin manager’s plugins method to iterate over all plugins.

Note, that while a plugin MAY register multiple plugins, currently it may only provide plugins of a common type. This restriction may be lifted in the future.

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")
        .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.

Provides the Error, ErrorKind, and Result type used in the rest of this crate.

The components required by a plugin host to load/unload plugins.

The components required to define a plugin API.