Version 1.0.0 · 2 functions · 1 crate
Functions
What use toml.qwer gives a program, with the types Quillo sees. To take only some, or under other names: use toml_parse, toml_stringify from toml (Quillo 0.6).
toml_parse(text: str) → anyor an errorTOML text as a map. Dates and times come as their text.
toml_stringify(value: any) → stror an errorA map as TOML text. TOML has no null: a field that is null is left out.
Get it
$ quillo install toml # toml.qwer into this folder$ quillo install toml --example # and its example, toml.qweOr with curl:
$ curl -O https://quillolang.org/plugins/files/toml.qwer$ curl -O https://quillolang.org/plugins/files/toml.qweThen, in your program, all of it or only what you call:
main.qwe
use toml.qweruse toml_parse, toml_stringify from toml // Quillo 0.6: only theseIt uses this crate, which cargo fetches the first time the plugin is built:
[dependencies]
toml = "0.8"Example
toml.qwe
// Reads a Cargo.toml-like file, and writes settings back.//// quillo run toml.qwe then open http://localhost:8080/packageuse "toml.qwer"route GET /package { let t = toml_parse(`[package]name = "shop"version = "1.4.0"released = 2026-03-01[dependencies]serde = { version = "1", features = ["derive"] }`)? { name: t.package.name, version: t.package.version, released: t.package.released, deps: keys(t.dependencies) }}route GET /settings = toml_stringify({ title: "Shop", owner: { name: "Ada", email: null }, ports: [8080, 8081] })?$ quillo run toml.qwe$ curl 'localhost:8080/package'$ curl 'localhost:8080/settings'Source
toml.qwer
//! TOML to values and back: Cargo.toml, pyproject.toml, app settings.//! version: 1.0.0//!//! [dependencies]//! toml = "0.8"use serde_json::{Map, Value};fn json_of(v: toml::Value) -> Value { match v { toml::Value::String(s) => Value::String(s), toml::Value::Integer(i) => Value::from(i), toml::Value::Float(f) => Value::from(f), toml::Value::Boolean(b) => Value::Bool(b), // A date or time is its text, as TOML writes it: `1979-05-27T07:32:00Z`. toml::Value::Datetime(d) => Value::String(d.to_string()), toml::Value::Array(a) => Value::Array(a.into_iter().map(json_of).collect()), toml::Value::Table(t) => Value::Object(t.into_iter().map(|(k, v)| (k, json_of(v))).collect::<Map<_, _>>()), }}/// TOML text as a map. Dates and times come as their text.pub fn toml_parse(text: &str) -> Result<Value, String> { text.parse::<toml::Table>().map(|t| json_of(toml::Value::Table(t))).map_err(|e| e.to_string())}/// A map as TOML text. TOML has no null: a field that is `null` is left out.pub fn toml_stringify(value: serde_json::Value) -> Result<String, String> { fn strip(v: Value) -> Value { match v { Value::Object(m) => Value::Object(m.into_iter().filter(|(_, v)| !v.is_null()).map(|(k, v)| (k, strip(v))).collect()), Value::Array(a) => Value::Array(a.into_iter().map(strip).collect()), v => v, } } if !value.is_object() { return Err("TOML's top level is a map".into()); } toml::to_string(&strip(value)).map_err(|e| e.to_string())}Related
.env files
dotenv.qwer · 1.0.0.env files read with their quoting rules and ${VAR} expansion, linted and compared with .env.example, and written or changed one key at a time with comments kept.8 views · 9 downloadsHCL hcl.qwer · 1.0.0HCL, the language of Terraform, Nomad and Packer files: read as values, expressions worked out from your variables, and written back.7 views · 6 downloadsINI ini.qwer · 1.0.0INI files read and written, sections and keys: php.ini, setup.cfg, .gitconfig and the settings of older software.8 views · 7 downloadsJava properties java_properties.qwer · 1.0.0Java .properties files read and written: Spring settings and translation bundles, with continued lines and \u escapes.6 views · 8 downloadsJSON5 json5.qwer · 1.0.0JSON5 and JSON with comments read as values: tsconfig.json and editor settings, with comments, trailing commas and unquoted keys.7 views · 8 downloadsProperty lists plist.qwer · 1.0.0Apple property lists, XML and binary: Info.plist, profiles and preferences read as values, and values written back as either.6 views · 9 downloadsThread
Thread 0 posts
On TOML: questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.