ini_puga

ini_puga

ini_puga handles ini files in an easy way, without dealing with errors(1) and thanks to generic types, only 2 methods get and get_vector are enought to get an integer, float, boolen, and so on.

(1) Load is the only one that may returns a Result IO:Error.

```rust use ini_puga::Ini;

const DEFAULT_CONFIG: &str = r#" my value without section = true pi=3.14159 [config] theme = Dark text scale = 1.2 empty value = screen width = 1080 resolutions = 640,480,3.5,whatever,720,1080 resolutions = use plugins = true themes path = themes/ plugins path = plugins/

[user data] name = José Puga id = 700101 fav lang = Rust fav pet = Rustacean "#;

let mut ini = Ini::new(); ini.read(DEFAULTCONFIG.tostring()); // Of course, you can also load from a file. // ini.load("config.ini").expect("*ERROR OPENING FILE *");

asserteq!(ini.get::("config", "text scale", 0.0), 1.2); asserteq!(ini.get::("user data", "id", 999), 700101); assert_eq!(ini.get::("user data", "id2", 999), 999);

//Vectors. Non valid values are inserted in the vector as default value let v = ini.getvector::("config", "resolutions", 240, ','); asserteq!(v[2], 240); assert_eq!(v[5], 1080); //Prints [640,480,240,240,720,1080] println!("{:?}", v);

let noname: String = String::from("anonymous"); assertne!( ini.get::("user data", "name", no_name), "anonymous");

// Check sections and keys asserteq!(ini.sectionexists("config"), true); asserteq!(ini.keyexists("NONEXISTENT section", "foo"), false);

// Case sensitive asserteq!(ini.keyexists("", "pi"), true); asserteq!(ini.keyexists("", "PI"), false); ```

License: MIT