Crate toml
A serde-compatible TOML-parsing library
TOML itself is a simple, ergonomic, and readable configuration format:
[package]
name = "toml"
[dependencies]
serde = "1.0"
The TOML format tends to be relatively common throughout the Rust community for configuration, notably being used by Cargo, Rust's package manager.
TOML values
A TOML document is represented with the Table type which maps String to the Value enum:
# use ;
Parsing TOML
The easiest way to parse a TOML document is via the Table type:
use Table;
let value = "foo = 'bar'"..unwrap;
assert_eq!;
The Table type implements a number of convenience methods and
traits; the example above uses FromStr to parse a str into a
Table.
Deserialization and Serialization
This crate supports serde 1.0 with a number of
implementations of the Deserialize, Serialize, Deserializer, and
Serializer traits. Namely, you'll find:
Deserialize for TableSerialize for TableDeserialize for ValueSerialize for ValueDeserialize for DatetimeSerialize for DatetimeDeserializer for de::DeserializerSerializer for ser::SerializerDeserializer for TableDeserializer for Value
This means that you can use Serde to deserialize/serialize the
Table type as well as Value and Datetime type in this crate. You can also
use the Deserializer, Serializer, or Table type itself to act as
a deserializer/serializer for arbitrary types.
An example of deserializing with TOML is:
use Deserialize;
let config: Config = from_str.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
You can serialize types in a similar fashion:
use Serialize;
let config = Config ;
let toml = to_string.unwrap;