[][src]Struct librustconfig::config::Config

pub struct Config { /* fields omitted */ }

Configuration file.

Implementations

impl Config[src]

pub fn new() -> Config[src]

Constructor. Create new Config struct.

Example

use librustconfig::config::Config;
 
let cfg = Config::new();

pub fn load_from_file(&mut self, file_name: &Path) -> Result<(), Errors>[src]

Load config file from file and parse it.

Example

use librustconfig::config::Config;
use std::path::Path;
 
let mut cfg = Config::new();
if cfg.load_from_file(Path::new("test.cfg")).is_ok() {
    // ...
}

pub fn load_from_string<S>(&mut self, config_string: S) -> Result<(), Errors> where
    S: Into<String>, 
[src]

Parse configuration from string.

Example

use librustconfig::config::Config;
 
let mut cfg = Config::new();
if cfg.load_from_string("root { value = 1 }").is_ok() {
    // ...
}

pub fn save_to_file(&mut self, file_name: &Path) -> Result<(), Errors>[src]

Save current config to file.

Example

use librustconfig::config::Config;
use std::path::Path;
use std::fs;
 
let mut cfg = Config::new();
if cfg.save_to_file(Path::new("test.cfg")).is_ok() {
     // ...
}
fs::remove_file(Path::new("test.cfg"));

pub fn include_dir(&mut self, path: &Path)[src]

Set current config include directory.

Example

use librustconfig::config::Config;
use std::path::Path;
 
let mut cfg = Config::new();
cfg.include_dir(Path::new("/config"));

pub fn value<S>(&self, path: S) -> Option<OptionReader> where
    S: Into<String>, 
[src]

Read value from path.

Example

use librustconfig::config::Config;
 
let cfg = Config::new();
match cfg.value("root.value") {
    Some(val) => { /* ... */ },
    None => { /* ... */ }
}

pub fn create_section<S>(&self, path: S) -> Option<OptionWriter> where
    S: Into<String>, 
[src]

Create new group section.

Example

use librustconfig::config::Config;
 
let cfg = Config::new();
match cfg.create_section("root") {
    Some(s) => { /* ... */ },
    None => { /* ... */ }
}

Trait Implementations

impl Drop for Config[src]

Destructor. Clear config and delete all allocated memory data.

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, 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.