Module dygpi::config[][src]

Expand description

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.

Example

The following uses the loaded configuration file to instantiate a plugin manager for the SoundEffectPlugin type, with any plugin libraries specified in the file.

use dygpi::config::PluginManagerConfiguration;
use dygpi::manager::PluginManager;
use dygpi::plugin::Plugin;

let config = load_config_file();

let plugin_manager: PluginManager<SoundEffectPlugin> =
    if config.contains_plugin_type(EFFECT_PLUGIN_ID) {
        config.make_manager_for_type(EFFECT_PLUGIN_ID).unwrap()
    } else {
        PluginManager::default()
    };

Example - Serde

Given the following simple configuration we can save it in any format supported by Serde.

use dygpi::config::PluginManagerConfiguration;

let mut config = PluginManagerConfiguration::default();
let _ = config.insert("sound_effects", &["beep", "boop"]);
let _ = config.insert("light_effects", &["bright", "mood"]);

In TOML:

[plugins]
light_effects = ["bright", "mood"]
sound_effects = ["boop", "beep"]

In JSON:

{
    "plugins": {
        "sound_effects": ["beep","boop"],
        "light_effects": ["bright","mood"]
    }
}

In YAML:

---
plugins:
  light_effects:
    - bright
    - mood
  sound_effects:
    - beep
    - boop

Structs

The plugin manager configuration itself. This is logically a map from a plugin type identifier and a list of library paths. The type identifier allows the configuration to partition the list of libraries so that multiple plugin managers may be created, for different plugin types, from the same configuration value or serialized file.