## When To Use std.toml In Zerolang, use `std.toml` for TOML validation, shallow field lookup, and typed scalar decode helpers. Runnable today: | API | Return | Notes | | --- | --- | --- | | `std.toml.validate(text)` | `Bool` | Checks the current TOML subset without allocation. | | `std.toml.validateBytes(bytes)` | `Bool` | Checks a `Span` TOML payload without allocation. | | `std.toml.field(bytes, key)` | `Maybe>` | Returns the raw value for a direct, dotted, or shallow table field. | | `std.toml.stringDecode(buffer, value)` | `Maybe>` | Decodes a TOML string value into caller storage. | | `std.toml.string(buffer, bytes, key)` | `Maybe>` | Looks up and decodes a TOML string field. | | `std.toml.u32(bytes, key)` | `Maybe` | Looks up and decodes an unsigned integer field. | | `std.toml.i32(bytes, key)` | `Maybe` | Looks up and decodes a signed integer field. | | `std.toml.bool(bytes, key)` | `Maybe` | Looks up and decodes a boolean field. | | `std.toml.arrayCount(value)` | `Maybe` | Counts items in a raw array value. | | `std.toml.arrayValue(value, index)` | `Maybe>` | Borrows a raw array item by ordinal. | | `std.toml.arrayString(buffer, value, index)` | `Maybe>` | Decodes a string array item into caller storage. | | `std.toml.arrayU32(value, index)` | `Maybe` | Decodes an unsigned integer array item. | | `std.toml.arrayI32(value, index)` | `Maybe` | Decodes a signed integer array item. | | `std.toml.arrayBool(value, index)` | `Maybe` | Decodes a boolean array item. | | `std.toml.writeKeyValueString(buffer, key, value)` | `Maybe>` | Writes one string key/value line. | | `std.toml.writeKeyValueU32(buffer, key, value)` | `Maybe>` | Writes one unsigned integer key/value line. | | `std.toml.writeKeyValueBool(buffer, key, value)` | `Maybe>` | Writes one boolean key/value line. | | `std.toml.writeTableHeader(buffer, table)` | `Maybe>` | Writes one table header line. | Metadata labels: - effects: parse - allocation behavior: allocation-free; decoded strings and writer output use caller storage - target support: target-neutral - error behavior: `Maybe` helpers return null on malformed or missing fields - ownership notes: returned raw fields borrow from the input span; decoded strings borrow from the caller buffer - examples: `conformance/native/pass/std-toml-basic.graph` ## Example ```zero pub fn main(world: World) -> Void raises { let input: Span = "[package]\nname = \"demo\"\n\n[features]\ngraph = true\nlevels = [1, 2, 3]\n" var name_buffer: [16]u8 = [0_u8; 16] let name: Maybe> = std.toml.string(name_buffer, input, "package.name") let graph: Maybe = std.toml.bool(input, "features.graph") let levels: Maybe> = std.toml.field(input, "features.levels") var count: Maybe = null if levels.has { count = std.toml.arrayCount(levels.value) } if std.toml.validateBytes(input) && name.has && graph.has && graph.value && count.has && count.value == 3 { check world.out.write("toml ok\n") } } ``` ## Design Notes The current TOML helper surface is deliberately narrow. It supports the package manifest subset used by Zero packages: tables, dotted keys, strings, booleans, integers, scalar arrays, and small writer helpers. Field lookup is shallow and table-aware, so `std.toml.string(buffer, input, "package.name")` can read `name` inside a `[package]` table. The helpers avoid hidden allocation. Use `field` when a raw value slice is enough, and use `string` or `stringDecode` when escape decoding into explicit caller storage is required.