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.

There are 2 more methods get_from_hex and get_vector_from_hex to convert hex numbers from strings to integer types.

(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 background color = faee89 font color = favourites colors = f53298,a0ffff,fa0e78 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 Hex numbers asserteq!(ini.getfromhex::("config", "background color", 0), 0xfaee89); //Empty or erroneus values always gets default. asserteq!(ini.getfromhex::("config", "font color", 25), 25); let vh = ini.getvectorfromhex::("config", "favourites colors", 0xffffff, ','); asserteq!(vh[1], 0xa0ffff); assert_eq!(vh[2], 0xfa0e78); //Prints [16069272,10551295,16387704] println!("{:?}", vh);

// 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);

// Print trait implemented println!("{}", ini); ```

License: MIT