Crates.io | tini |
lib.rs | tini |
version | 1.3.0 |
source | src |
created_at | 2016-03-20 10:06:37.460983 |
updated_at | 2021-11-16 15:36:34.999354 |
description | A tiny ini parsing library |
homepage | |
repository | https://github.com/pinecrew/tini |
max_upload_size | |
id | 4499 |
size | 43,984 |
Add tini
to your Cargo.toml
, for example:
[dependencies]
tini = "1.3"
extern crate tini;
use tini::Ini;
fn main() {
// Read example.ini file from examples directory
let config = Ini::from_file("./examples/example.ini").unwrap();
// Read name3 key from section_one
let name3: String = config.get("section_one", "name3").unwrap();
// Read list of values
let frst5: Vec<bool> = config.get_vec("section_three", "frst5").unwrap();
println!("name3 = {}", name3);
println!("frst5 = {:?}", frst5);
// Result:
// name3 = example text
// frst5 = [true, false, true]
}
extern crate tini;
use tini::Ini;
fn main() {
// Create ini structure
let conf = Ini::new() // initialize Ini
.section("params") // create `params` section
.item("pi", 3.14) // add `pi` key
.item_vec("lost", &[4, 8, 15, 16, 23, 42]) // add `lost` list
.section("other") // create another section
.item("default", "hello world!"); // add `default` key to `other` section
// At any time you can add new parameters to the last created section
// < some code >
// Now write ini structure to file
conf.to_file("output.ini").unwrap();
// Now `output.ini` contains
// -----------------------------
// [params]
// pi = 3.14
// lost = 4, 8, 15, 16, 23, 42
//
// [other]
// default = hello world!
// -----------------------------
}
See more examples in documentation.