stringify(value: TOML Value) - > Result<string, string>- 수신자
- 해당 없음
- 최소 인자 수
- 1
- 최대 인자 수
- 1
Declaration and parameters
링크사용 조건
기본 포함 · 미정
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.
수신자
매개변수 제약
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.
결과
The declared result type is Result<string, string>.
효과
실패
Result and effects
링크Write a TOML root table in deterministic key order with LF record endings.
Related entries
링크Write deterministic TOML documents
링크Write 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.
이유
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.
Reject a scalar as a complete TOML document
링크import 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
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
root table required
Write the binary64 value rather than its input spelling
링크import 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
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
x = 0.1