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

pub struct Config { /* fields omitted */ }

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

impl Config[src]

pub fn new(file: &str) -> Self[src]

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.

pub fn notifier(&self) -> ChangeNotifier[src]

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

pub fn current(&self) -> Handle[src]

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.

pub async fn load(&self) -> Result<()>[src]

Forces the config to read the underlying file.

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

pub async fn store(&self, config: &str) -> Result<()>[src]

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);

pub fn load_from_string(
    &self,
    data: &str,
    last_modified: Option<SystemTime>
) -> Result<()>
[src]

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

impl !RefUnwindSafe for Config

impl Send for Config

impl Sync for Config

impl Unpin for Config

impl !UnwindSafe for Config

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.