stringify(value: TOML Value) - > Result<string, string>- Модуль
- std.
toml → - Получатель
- Неприменимо
- Минимальное число аргументов
- 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