Struct simple_config_parser::Config [−][src]
Expand description
Config Struct
Fields
data: Vec<[String; 2]>
Raw Data of the Config
Implementations
Config Implementation
Create a new Config struct
Example
// Import Lib
use simple_config_parser::Config;
let mut cfg = Config::new();
Reads and parses config from a file
If called more than one time it will append the current values. So the recently appended valued will take priority
Example
// Import Lib
use simple_config_parser::Config;
// Create a new config with a file
let mut cfg = Config::new().file("config.cfg").unwrap();
// Read a value
assert_eq!(cfg.get_str("hello").unwrap(), "World");
Parses config from text or anything that impls fmt::Display
Example
// Import Lib
use simple_config_parser::Config;
// Create a new config with text
let mut cfg = Config::new().text("hello = World").unwrap();
// Read a value
assert_eq!(cfg.get_str("hello").unwrap(), "World");
Get a value from config as ayn type (That Impls str::FromStr)
Example
// Import Lib
use simple_config_parser::Config;
// Create a new config with text
// I knew a lot more of pi at one point :P
let mut cfg = Config::new().text("pi = 3.14159265358979").unwrap();
// Read a value
assert_eq!(cfg.get::<f32>("pi").unwrap(), 3.14159265358979);
Get a value from config as a String
Example
// Import Lib
use simple_config_parser::Config;
// Create a new config with text
let mut cfg = Config::new().text("pi = 3.14159265358979").unwrap();
// Read a value
assert_eq!(cfg.get_str("pi").unwrap(), "3.14159265358979");