stringify(value: TOML Value) - > Result<string, string>- Module
- std.
toml - Receiver
- Not applicable
- Minimum arity
- 1
- Maximum arity
- 1
Declaration and parameters
LinkAvailability
Included by default: Pending
Import std.toml in language mode 5.21.
The current compiler selects std/toml.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1798 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 70 - compiler/crates/topaz_resolve/src/std/521/toml.tpz at
b48527d0a174· 4 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1798 - compiler/crates/topaz_self_frontend/topaz/checker/builtin_signatures.tpz at
b48527d0a174· 210 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1973 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
b48527d0a174· 978 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1255
Receiver
Parameter constraints
stringify accepts a TOMLValue whose root is a table. A scalar or array root returns Err because it is not a TOML document. An empty table becomes empty text.
Each table writes its scalar and array entries before child table sections. Both groups follow the decoded key order. Arrays retain element order. Table headers use the complete dotted path. A noninitial table section is separated by one blank line.
Assignments use one space on either side of the equals sign. Inline arrays and tables use a comma followed by one space. Every nonempty document uses LF line endings and ends with one LF. Comments, indentation and source ordering are not reproduced.
Bare keys use the TOML ASCII key alphabet. Other keys and string values use basic quoted strings with deterministic escaping. Integers use decimal digits without separators. Finite floats use the shortest binary64 roundtrip value and retain a decimal point or exponent to distinguish a float from an integer. Positive and negative zero are written as 0. and -. Nonfinite values use inf, - or nan.
Dates and times use their TOML kind, a capital T separator and a capital Z for a zero offset. Local kinds retain their lack of an offset. Fractional seconds omit redundant trailing zeroes.
The value argument is evaluated once. Serialization performs no I/O, does not mutate the value and returns Err without partial output when the value cannot form a document. Parse the result with toml. to recover the same TOML kinds and values.
Result
The declared result type is Result<string, string>.
Effects
Failures
Result and effects
LinkWrite a TOML root table in deterministic key order with LF record endings.
Related entries
LinkWrite deterministic TOML documents
LinkWrite deterministic TOML documents
stringify accepts a TOMLValue whose root is a table. A scalar or array root returns Err because it is not a TOML document. An empty table becomes empty text.
Each table writes its scalar and array entries before child table sections. Both groups follow the decoded key order. Arrays retain element order. Table headers use the complete dotted path. A noninitial table section is separated by one blank line.
Assignments use one space on either side of the equals sign. Inline arrays and tables use a comma followed by one space. Every nonempty document uses LF line endings and ends with one LF. Comments, indentation and source ordering are not reproduced.
Bare keys use the TOML ASCII key alphabet. Other keys and string values use basic quoted strings with deterministic escaping. Integers use decimal digits without separators. Finite floats use the shortest binary64 roundtrip value and retain a decimal point or exponent to distinguish a float from an integer. Positive and negative zero are written as 0. and -. Nonfinite values use inf, - or nan.
Dates and times use their TOML kind, a capital T separator and a capital Z for a zero offset. Local kinds retain their lack of an offset. Fractional seconds omit redundant trailing zeroes.
The value argument is evaluated once. Serialization performs no I/O, does not mutate the value and returns Err without partial output when the value cannot form a document. Parse the result with toml. to recover the same TOML kinds and values.
Why
A deterministic writer supports stable configuration diffs. Requiring a table root makes its successful output usable as a complete TOML document, and numeric normalization follows the stored numeric value.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1329 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1356 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1387 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 137 -
topaz.stdlib.contract.toml-stringifyatworking-tree - topaz.decision.toml-one-and-conversion.1 at
topaz.decisi
Reject a scalar as a complete TOML document
Linkimport std.jsonimport std.tomlimport std.testimport std.iolet tree = test.assertOk(json.parse("7"))let value = test.assertOk(toml.fromJson(tree))match (toml.stringify(value)) {case Ok(_) => io.writeLine("accepted")case Err(_) => io.writeLine("root table required")}
root table required
Expected result
Expected result
Execution completes. Exit code 0.
root table required
Source evidence
- compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1329 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1356 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1387 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 137 -
topaz.stdlib.contract.toml-stringifyatworking-tree - topaz.decision.toml-one-and-conversion.1 at
topaz.decisi
Write the binary64 value rather than its input spelling
Linkimport std.tomlimport std.testimport std.iolet value = test.assertOk(toml.parse("x = 0.10000000000000001\n"))io.writeLine(test.assertOk(toml.stringify(value)))
x = 0.1
Expected result
Expected result
Execution completes. Exit code 0.
x = 0.1
Source evidence
- compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1329 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1356 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1387 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 137 -
topaz.stdlib.contract.toml-stringifyatworking-tree - topaz.decision.toml-one-and-conversion.1 at
topaz.decisi