Skip to content

Latest commit

 

History

History
91 lines (63 loc) · 2.04 KB

README.md

File metadata and controls

91 lines (63 loc) · 2.04 KB

rust-toml Build Status

A TOML configuration file parser for Rust.

Quickstart

Given the following TOML configuration file:

# products.toml
[global]

# ...

[db]

  [[db.products]]

  id = 1
  name = "prod1"

  [[db.products]]

  id = 2
  name = "prod2"

You can access it like in the example below:

extern crate toml = "github.com/mneumann/rust-toml#toml:0.1";

fn main() {
    let root = toml::parse_from_file("products.toml").unwrap();
    let id1  = root.lookup("db.products.0.id").get_int();
    let name2 = root.lookup("db.products.1.name").get_str();
    match (id1, name2) {
        (Some(id1), Some(ref name2)) => {
            println!("id1: {}, name2: {}", id1, name2)
        }
        _ => {
            println!("Not found")
        }
    }
}

Benchmark

I did a pretty non-scientific benchmark against go-toml for a very large document (3 million lines). Not that it would matter in any way, but it shows that rust-toml is about three times as fast.

Conformity

I am using this test suite to check for conformity to the TOML spec. The test cases are also included in this git repo, you can run them with this command:

./bin/testsuite ./tests

Alternatively you can run it with the test runner from the original test-suite using this command (see it's homepage for details on how to install it):

$HOME/go/local/bin/toml-test rust-toml/bin/testsuite

Right now all 63 tests pass, none fails.

License

rust-toml is under the MIT license, see LICENSE-MIT for details.

Copyright (c) 2014 by Michael Neumann.