[][src]Trait tari_common::configuration::loader::ConfigExtractor

pub trait ConfigExtractor {
    fn set_default(cfg: &mut Config);
fn extract_configuration(
        cfg: &Config,
        network: Network
    ) -> Result<Self, ConfigurationError>
    where
        Self: Sized
; }
Deprecated since 0.0.10:

Please use ConfigPath and ConfigLoader traits instead

Extract parts of the global Config file into custom configuration objects that are more specific and localised. The expected use case for this is to use load_configuration to load the global configuration file into a Config object. This is then used to generate other, localised configuration objects, for example, MempoolConfig etc.

Example

This code runs with edition 2018
struct MyConf {
    foo: usize,
}

impl ConfigExtractor for MyConf {
    fn set_default(cfg: &mut Config) {
        cfg.set_default("main.foo", 5);
        cfg.set_default("test.foo", 6);
    }

    fn extract_configuration(cfg: &Config, network: Network) -> Result<Self, ConfigurationError> {
        let key = match network {
            Network::MainNet => "main.foo",
            Network::Rincewind => "test.foo",
        };
        let foo = cfg.get_int(key).map_err(|e| ConfigurationError::new(&key, &e.to_string()))? as usize;
        Ok(MyConf { foo })
    }
}

Required methods

fn set_default(cfg: &mut Config)

Deprecated since 0.0.10:

Please use ConfigPath and ConfigLoader traits instead

Provides the default values for the Config object. This is used before load_configuration and ensures that all config parameters have at least the default value set.

fn extract_configuration(
    cfg: &Config,
    network: Network
) -> Result<Self, ConfigurationError> where
    Self: Sized

Deprecated since 0.0.10:

Please use ConfigPath and ConfigLoader traits instead

After load_configuration has been called, you can construct a specific configuration object by calling extract_configuration and it will create the object using values from the config file / environment variables

Loading content...

Implementors

Loading content...