[][src]Struct cfg_lib::config::Config

pub struct Config {
    pub no_duplicates: bool,
    // some fields omitted
}

Represents a CFG configuration.

Fields

no_duplicates: bool

If true, loaded configurations aren't allowed to have duplicate keys. If false, duplicate keys are allowed, and values encountered later overwrite values encountered earlier for the same key.

Methods

impl Config[src]

pub fn new() -> Self[src]

Return an empty configuration with default settings.

pub fn from_file(file_path: &str) -> StdResult<Self, ConfigError>[src]

Return a new configuration loaded from the file named by file_path.

pub fn add_include(&mut self, dir: &str)[src]

Add the directory dir to the end of the include path.

pub fn load_from_file(&mut self, file_path: &str) -> StdResult<(), ConfigError>[src]

Load the configuration from the file named by file_path.

pub fn load(&mut self, r: Box<dyn Read>) -> StdResult<(), ConfigError>[src]

Load the configuration from the reader r.

pub fn set_context(&mut self, context: HashMap<String, Value>)[src]

Set the given hashmap context as the place to look up identifiers encountered in the configuration.

pub fn contains_key(&self, key: &str) -> bool[src]

Returns true if this configuration contains the simple key key (i.e. not a path), else false.

pub fn as_mapping(
    &self,
    unwrap_configs: bool
) -> StdResult<HashMap<String, Value>, ConfigError>
[src]

Convert the configuration to a HashMap.

If unwrap_configs is true, nested configurations are also converted to mappings. Otherwise, they are left as is.

pub fn get(&self, key: &str) -> StdResult<Value, ConfigError>[src]

Returns the value for the specified configuration key.

key can either be an identifier or a valid path.

Trait Implementations

impl Clone for Config[src]

impl Debug for Config[src]

impl Default for Config[src]

impl Display for Config[src]

impl PartialEq<Config> for Config[src]

impl StructuralPartialEq for Config[src]

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]

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

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

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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.

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.