4 releases (breaking)

0.4.0 Sep 14, 2020
0.3.0 Sep 11, 2020
0.2.0 Sep 14, 2016
0.1.1 Mar 20, 2016

#11 in Configuration

Download history 170/week @ 2020-06-08 431/week @ 2020-06-15 108/week @ 2020-06-22 194/week @ 2020-06-29 473/week @ 2020-07-06 159/week @ 2020-07-13 488/week @ 2020-07-20 408/week @ 2020-07-27 288/week @ 2020-08-03 197/week @ 2020-08-10 510/week @ 2020-08-17 499/week @ 2020-08-24 298/week @ 2020-08-31 271/week @ 2020-09-07 362/week @ 2020-09-14 837/week @ 2020-09-21

1,501 downloads per month
Used in libscroll

BSD-3-Clause

26KB
478 lines

tini — A tiny INI parsing library, written in Rust

Gitter Build Status Crates

| Documentation | Examples |

Usage

Add tini to your Cargo.toml, for example:

[dependencies]
tini = "0.4"

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("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 in examples folder or in documentation.

No runtime deps