Struct apollo_framework::config::Config[][src]

pub struct Config { /* fields omitted */ }
Expand description

Provides access to the system configuration.

Most probably a config instance is installed by the Builder and can be obtained via platform.require::<Config>(). Note that it is highly recommended to register a change listener by calling Config::notifier() as we expect all components to pick up config changes without restarting the application.

Implementations

Creates a new config reading the given file.

Note that this will not install a change listener. This is only done by the install function.

Obtains a change notifier which receives a message once the config changed.

Obtains a handle to the currently loaded configuration.

Note that this is a fairly efficient operation but still provides some overhead. Therefore this shouldn’t be placed in an inner loop.

Forces the config to read the underlying file.

Note that this is normally called by the framework and should not be invoked manually.

Loads a configuration from the given string instead of a file.

This is intended to be used in test environments where we cannot / do not want to load a config file from disk.

Example
let config = Config::new("apollo_test_config.yml");

// Remove any left over file...
std::fs::remove_file("apollo_test_config.yml");

// Write a config file...
assert_eq!(config.store("
server:
    port: 12345
").await.is_ok(), true);

// Load it back and verify its contents (in a fully running Apollo, this would
// happen automatically via the config watcher...)
assert_eq!(config.load().await.is_ok(), true);
assert_eq!(config.current().config()["server"]["port"].as_i64().unwrap(), 12345);

// Writing an invalid config file is prevented...
assert_eq!(config.store("server: \"test").await.is_err(), true);

// Therefore the original config is still present...
assert_eq!(config.load().await.is_ok(), true);
assert_eq!(config.current().config()["server"]["port"].as_i64().unwrap(), 12345);

Loads a configuration from the given string instead of a file.

This is intended to be used in test environments where we cannot / do not want to load a config file from disk.

Example
use std::time::Instant;
let config = Config::new("somefile.yml");
config.load_from_string("
server:
    port: 12345
", None);

assert_eq!(config.current().config()["server"]["port"].as_i64().unwrap(), 12345);

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.