[−][src]Trait tari_common::configuration::loader::ConfigExtractor
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
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)
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,
cfg: &Config,
network: Network
) -> Result<Self, ConfigurationError> where
Self: Sized,
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