toml-plugin
stableFull-featured TOML parser and serializer with file I/O, dot-path get/set, validation, key enumeration, and deep merge — backed by the Rust `toml` crate.
use plugin toml-plugin::{parse, stringify, parse_file, …} Functions (9)
- parse Parse a TOML string into a table
- stringify Serialize a table to a pretty-printed TOML string
- parse_file Read and parse a TOML file from disk
- write_file Serialize a table and write it to a TOML file
- get Read a nested value using a dot-separated path
- set Write a nested value using a dot-separated path
- validate Check whether a string is valid TOML
- keys List the top-level keys of a table
- merge Deep-merge two tables, overlay wins on conflict
Parse a TOML string into a table
Parses a TOML-formatted string and returns it as a Zolo table. TOML arrays become integer-keyed tables; TOML tables become string-keyed tables. Datetime values are returned as strings.
use plugin toml-plugin::{parse}
let config = parse('[server]\nhost = "localhost"\nport = 8080')
print(config["server"]["host"])
print(config["server"]["port"])
Serialize a table to a pretty-printed TOML string
Serializes a Zolo table to a pretty-printed TOML string. Integer-keyed tables are serialized as TOML arrays; string-keyed tables become TOML tables.
use plugin toml-plugin::{stringify}
let data = #{"name": "Alice", "age": 30, "active": true}
let toml_str = stringify(data)
print(toml_str)
Read and parse a TOML file from disk
Reads the file at path and parses its contents as TOML. The path is resolved relative to the plugin's working directory. Raises an error if the file cannot be read or the content is invalid TOML.
use plugin toml-plugin::{parse_file}
let config = parse_file("config/settings.toml")
print(config["database"]["url"])
Serialize a table and write it to a TOML file
Serializes table to a TOML string and writes it to the file at path, creating or overwriting the file. The path is resolved relative to the plugin's working directory.
use plugin toml-plugin::{parse_file, set, write_file}
let config = parse_file("config/app.toml")
let updated = set(config, "server.port", 9090)
write_file("config/app.toml", updated)
Read a nested value using a dot-separated path
Reads a nested value using a dot-separated path string. Returns nil if any intermediate key is missing. Useful for safely reading deeply nested TOML structures without manual indexing.
use plugin toml-plugin::{parse, get}
let config = parse('[db]\nhost = "localhost"\nport = 5432')
let host = get(config, "db.host")
let port = get(config, "db.port")
print("{host}:{port}")
Write a nested value using a dot-separated path
Returns a new table with the value at the dot-separated path set to value. Intermediate tables are created if they do not exist. The original table is not modified.
use plugin toml-plugin::{parse, set, stringify}
let config = parse('version = "1.0"')
let updated = set(config, "server.host", "0.0.0.0")
let updated2 = set(updated, "server.port", 443)
print(stringify(updated2))
Check whether a string is valid TOML
Returns true if the string is valid TOML, false otherwise. Does not raise an error on invalid input, making it useful for user-provided config validation.
use plugin toml-plugin::{validate}
print(validate('[valid]\nkey = "value"'))
print(validate("this is not : valid toml ==="))
List the top-level keys of a table
Returns a list of the top-level key names of a table as strings. The order reflects the order keys appear in the table.
use plugin toml-plugin::{parse, keys}
let config = parse('name = "app"\nversion = "1.0"\ndebug = false')
let k = keys(config)
print(k[1])
print(k[2])
Deep-merge two tables, overlay wins on conflict
Deep-merges two tables. Keys from overlay overwrite keys in base. When both values are tables, they are merged recursively. Non-table conflicts are resolved in favor of overlay.
use plugin toml-plugin::{parse, merge, stringify}
let base = parse('[db]\nhost = "localhost"\nport = 5432')
let override = parse('[db]\nport = 5433\ntimeout = 30')
let merged = merge(base, override)
print(stringify(merged))