libreadconfig

This is a rust library that is meant to help with using config files.

Usage

Using the library is very simple, the following is an example to get you started:

sh user@example $ cat /tmp/example.conf cat: /tmp/example.conf: No such file or directory user@example $ cat /etc/example.conf name foo surname bar very_important_option fizz user@example $ cat /var/example.conf name bar surname foo very_important_option fizz

```rust extern crate readconfig

use readconfig::Configuration;

fn main() { let cfg = Configuration::new(&["/tmp/example.conf", "/etc/example.conf", "/var/example.conf"]).unwrap(); println!("{}", cfg.get_option("name").unwrap()); } ```

sh user@example $ ./executable foo

The result here is foo since it is the value contained within the first valid configuration file.

Docs

Structs

Configuration

rust /// A struct that contains a file buffer which represents a configuration /// file. It can then be used to read options from. pub struct Configuration { file_buffer: String, }

Functions

Configuration::new()

rust /// The creator for Configuration struct, it takes an array of filepaths /// and then reads from the first one that's valid. It then returns /// A configuration struct with the files configuration. pub fn new(paths: &[&str]) -> Result<Self, std::io::Error>

Configuration.get_option()

rust /// Takes the name of an option and returns the value as a String pub fn get_option(self, option_name: &str) -> Result<String, ()>