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.
- Can get a Vector from values with a separator
- Indentation doesnt matter.
- CASE sensitive!.
- [Config] is NOT the same as [config]
- Blank lines are ignored
- Keys and values are trimmed left and right.
(1) Load is the only one that may returns a Result IO:Error.
use 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 = new;
ini.read;
// Of course, you can also load from a file.
// ini.load("config.ini").expect("***ERROR OPENING FILE ***");
assert_eq!;
assert_eq!;
assert_eq!;
//Vectors. Non valid values are inserted in the vector as default value
let v = ini.;
assert_eq!;
assert_eq!;
//Prints [640,480,240,240,720,1080]
println!;
let no_name: String = Stringfrom;
assert_ne!;
// Check Hex numbers
assert_eq!;
//Empty or erroneus values always gets default.
assert_eq!;
let vh = ini.;
assert_eq!;
assert_eq!;
//Prints [16069272,10551295,16387704]
println!;
// Check sections and keys
assert_eq!;
assert_eq!;
let sn = ini.get_sections_names;
//len +1 because empty section always exists
assert_eq!;
//Prints (random order) ["config", "", "user data"]
println!;
let ks = ini.get_keys_from_section;
assert_eq!;
//Prints (random order) ["my value without section", "pi"]
println!;
// Case sensitive
assert_eq!;
assert_eq!;
// Print trait implemented
println!;
License: MIT