std::encoding::tomlTOML parsing and generation.
Parse TOML documents into values, build new tables programmatically, and serialize back to TOML text.
import std.encoding.toml;
fn main() {
let doc = match toml.parse("[package]\nname = \"hew\"") {
.Ok(value) => value,
.Err(_) => panic("invalid TOML"),
};
let pkg = doc.get_field("package");
let name = pkg.get_field("name");
println(name.get_string()); // "hew"
name.free();
pkg.free();
doc.free();
}
parseParse a TOML string into a Value.
Returns Err(ParseError.Invalid(message)) with the native parser message
when parsing fails. Match on ParseError.Invalid(message) to recover the
original parser message.
stringifySerialize val back to a TOML string without panicking.
A TOML document root must be a table. An integer, string, or array root serializes to no text at all, which is exactly what an empty table serializes to, so the two are only distinguishable through this result.
encodeEncode any data value as a TOML document. Records encode as objects keyed by field name in declaration order.
decodeDecode a TOML document as T. A failure names the path of the value that did
not fit, for example Type: .tags[1]: expected string, found integer.
ParseErrorStructured error type for TOML parsing failures.
Use Result<Value, ParseError> with parse for structured error
handling. Import std.encoding.toml when matching on the returned error
value so you can use the existing unqualified
ParseError.Invalid(message) constructor/pattern style.
Invalid(string)The input was not valid TOML. Carries the native parser message.
ValueAn opaque TOML value.
Represents any TOML type: string, integer, float, boolean, array,
table, or datetime. TOML has no null value.
Values close automatically at the end of their ownership scope;
close() performs the same release explicitly.
ValueMethodsMethods available on a TOML Value.
This module retains an independent resource carrier.
Return the type tag (0=null reserved, 1=bool, 2=i64, 3=float, 4=string, 5=array, 6=table, 7=datetime).
Extract the string value.
Extract the integer value.
Extract the floating-point value.
Extract the boolean value (0 or 1).
Look up a field by key in a TOML table.
Return the number of elements in a TOML array.
Return the element at the given index in a TOML array.
Serialize the value back to a TOML string.
Panics if the value cannot be a TOML document root. Only a table can:
an integer, string, or array root serializes to no text at all, which
is exactly what an empty table serializes to. Use stringify()
when that failure should be returned as an error.
Consuming compatibility alias for the inherent close().
Set a string field on a table. Returns the table for chaining.
Set an integer field. Returns the table for chaining.
Set a float field. Returns the table for chaining.
Set a boolean field. Returns the table for chaining.
Set a Value child on a table. The child is consumed. Returns the table.
Push a Value onto an array. The child is consumed. Returns the array.
Push an integer onto an array. Returns the array.
Push a string onto an array. Returns the array.
Push a float onto an array. Returns the array.
Push a boolean onto an array. Returns the array.