toml
TOML serialization and deserialization.
Types
| Type | Description |
|---|---|
Data |
A value decoded from TOML. |
Encodable |
A value that encodes as TOML. |
Data = (Bool | Int | Float | Str | Array[Data] | Dict[Str, Data])
A value decoded from TOML.
Encodable = (Bool | Int | Float | Str | Sym | Array[Encodable] | Tuple[...Encodable] | Record[...{...Sym: Encodable}] | Dict[Str | Sym, Encodable])
A value that encodes as TOML.
Functions
decode toml -> Data
Parses a TOML string into a Do value.
| TOML Value | Do Type |
|---|---|
| boolean | Bool |
| integer | Int |
| float | Float |
| string | Str |
| array | Array |
| table | Dict |
Full documents and bare TOML values such as numbers, arrays, and inline tables are accepted.
Parameters
| Name | Type | Description |
|---|---|---|
toml |
Str |
TOML input to parse. |
Errors
ValueError if the input is invalid TOML or uses TOML datetime, date, or
time values, which are not mapped by this module yet.
Example
assert_eq (decode "42") 42
assert_eq (decode "[1, 2, 3]") [1, 2, 3]
let doc = decode |
title = "Example"
[server]
port = 8080
assert_eq $doc["title"] "Example"
assert_eq $doc["server"]["port"] 8080
encode value -> Str
Serializes a Do value to a TOML string.
| Do Type | TOML Value |
|---|---|
Bool |
boolean |
Int |
integer |
Float |
float |
Str |
string |
Sym |
string |
Array |
array |
Tuple |
array |
Dict |
table |
Record |
table |
Top-level dicts and records serialize as documents, while other values serialize as values.
Parameters
| Name | Type | Description |
|---|---|---|
value |
Encodable |
The value to serialize. |
Errors
TypeError if a value is not TOML-representable, including nil, binary
data, custom objects, or tables with non-string and non-symbol keys.