본문으로 건너뛰기
토파즈6.0 · 출시 전
다운로드 →

문서 검색

명세 6.0

방향키로 결과를 고르고 Enter를 눌러 여세요.

API 이름, 진단 번호, 규칙 또는 프로젝트 주제를 입력하세요.

    라이브러리

    std.toml.stringify

    Serializes a TOMLValue as text.

    stringify(value: TOMLValue) -> 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.0 and -0.0. Nonfinite values use inf, -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.parse 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

    링크

    std.toml →

    Write deterministic TOML documents

    링크
    규칙topaz.stdlib.contract.toml-stringify.rule

    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.0 and -0.0. Nonfinite values use inf, -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.parse 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

    링크
    main.tpzReject a scalar as a complete TOML document플레이그라운드 열기 →
    1. import std.json
    2. import std.toml
    3. import std.test
    4. import std.io
    5. let tree = test.assertOk(json.parse("7"))
    6. let value = test.assertOk(toml.fromJson(tree))
    7. match (toml.stringify(value)) {
    8. case Ok(_) => io.writeLine("accepted")
    9. case Err(_) => io.writeLine("root table required")
    10. }
    기대 출력종료 코드 0
    root table required
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. root table required

    Write the binary64 value rather than its input spelling

    링크
    main.tpzWrite the binary64 value rather than its input spelling플레이그라운드 열기 →
    1. import std.toml
    2. import std.test
    3. import std.io
    4. let value = test.assertOk(toml.parse("x = 0.10000000000000001\n"))
    5. io.writeLine(test.assertOk(toml.stringify(value)))
    기대 출력종료 코드 0
    x = 0.1
    
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. x = 0.1

    메뉴

    다운로드 →