9 releases (4 stable)

1.3.0 Nov 16, 2021
1.2.0 May 23, 2021
1.0.0 Jan 17, 2021
0.9.0 Jan 11, 2021
0.1.1 Mar 20, 2016

#64 in Configuration

Download history 330/week @ 2024-03-13 423/week @ 2024-03-20 412/week @ 2024-03-27 317/week @ 2024-04-03 379/week @ 2024-04-10 510/week @ 2024-04-17 461/week @ 2024-04-24 341/week @ 2024-05-01 323/week @ 2024-05-08 385/week @ 2024-05-15 452/week @ 2024-05-22 506/week @ 2024-05-29 721/week @ 2024-06-05 353/week @ 2024-06-12 437/week @ 2024-06-19 286/week @ 2024-06-26

1,903 downloads per month
Used in 10 crates (5 directly)

BSD-3-Clause

44KB
704 lines

tini — A tiny INI parsing library

Rust Crates Docs

Usage

Add tini to your Cargo.toml, for example:

[dependencies]
tini = "1.3"

How to use

Read ini configuration from file

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]
}

Create ini configuration and write to file

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.

No runtime deps