Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

toml

The toml module provides TOML serialization and deserialization. Like json::read, toml::read uses type-directed deserialization, and the writers write a value as its type says, as json::write_str does: a document is a struct or a Map, and an Array<(string, T)> is refused. As with json, only a value whose type says nothing (Any) is written by its contents, where an array of (string, _) pairs in key order is a table.

/// Parse TOML from a string or bytes.
///
/// To parse a stream, read it first — `toml::read(Read::read_all(f)?)`.
val read: fn<'b: Concrete>(input: [string, bytes]) -> Result<'b, [`TomlErr(string), `InvalidCast(string)]>;

/// Serialize a value to a TOML string.
val write_str: fn<'a: Data>(?#pretty: bool, value: 'a) -> Result<string, `TomlErr(string)>;

/// Serialize a value to TOML bytes.
///
/// To write to a stream, write the bytes — `Write::write_exact(f, toml::write_bytes(v)?)`.
val write_bytes: fn<'a: Data>(?#pretty: bool, value: 'a) -> Result<bytes, `TomlErr(string)>;

Example


type Config = {
    host: string,
    port: i64,
    debug: bool
};

let cfg: Config = toml::read(sys::fs::read_all("config.toml")?)?;
let out = toml::write_str(#pretty: true, cfg)?;