toml
The toml module provides TOML parsing and serialization. It converts between
TOML text and Shape values (HashMaps, arrays, strings, numbers, booleans).
Import
Section titled “Import”use std::core::tomlFunctions
Section titled “Functions”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"]) // 8080toml::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)toml::is_valid(text: string) -> bool
Section titled “toml::is_valid(text: string) -> bool”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\"") // truetoml::is_valid("= invalid") // false