Skip to content

toml

The toml module provides TOML parsing and serialization. It converts between TOML text and Shape values (HashMaps, arrays, strings, numbers, booleans).

use std::core::toml

toml::parse(text: string) -> Result<HashMap, string>

Section titled “toml::parse(text: string) -> Result<HashMap, string>”

Parse a TOML string into Shape values. Tables become HashMaps, arrays become arrays, and scalar values map to their Shape equivalents.

let config = toml::parse("""
[server]
host = "localhost"
port = 8080
debug = true
""")?
print(config["server"]["host"]) // "localhost"
print(config["server"]["port"]) // 8080

toml::stringify(value) -> Result<string, string>

Section titled “toml::stringify(value) -> Result<string, string>”

Serialize a Shape value to a TOML string. HashMaps become tables, arrays become TOML arrays, and scalars are formatted according to the TOML specification.

let text = toml::stringify({
name: "my-project",
version: 1,
dependencies: { shape: "0.1.0" }
})?
print(text)

Check whether a string is valid TOML without parsing it into values. Returns true if the string parses successfully, false otherwise.

toml::is_valid("key = \"value\"") // true
toml::is_valid("= invalid") // false
  • json — JSON parsing and serialization
  • yaml — YAML parsing and serialization