dtolnay / serde-yaml

Strongly typed YAML library for Rust
Apache License 2.0
965 stars 164 forks source link

Handwrite a better Debug for Value #287

Closed dtolnay closed 2 years ago

dtolnay commented 2 years ago

YAML input:

Null: ~
Bool: true
Number: 1
String: ...
Sequence:
  - true
EmptySequence: []
Mapping:
  k: v
EmptyMapping: {}
Tagged: !tag true

Before:

Mapping(
    Mapping {
        map: {
            String(
                "Null",
            ): Null,
            String(
                "Bool",
            ): Bool(
                true,
            ),
            String(
                "Number",
            ): Number(
                PosInt(
                    1,
                ),
            ),
            String(
                "String",
            ): String(
                "...",
            ),
            String(
                "Sequence",
            ): Sequence(
                [
                    Bool(
                        true,
                    ),
                ],
            ),
            String(
                "EmptySequence",
            ): Sequence(
                [],
            ),
            String(
                "Mapping",
            ): Mapping(
                Mapping {
                    map: {
                        String(
                            "k",
                        ): String(
                            "v",
                        ),
                    },
                },
            ),
            String(
                "EmptyMapping",
            ): Mapping(
                Mapping {
                    map: {},
                },
            ),
            String(
                "Tagged",
            ): Tagged(
                TaggedValue {
                    tag: !tag,
                    value: Bool(
                        true,
                    ),
                },
            ),
        },
    },
)

After:

Mapping {
    "Null": Null,
    "Bool": Bool(true),
    "Number": Number(1),
    "String": String("..."),
    "Sequence": Sequence [
        Bool(true),
    ],
    "EmptySequence": Sequence [],
    "EmptyMapping": Mapping {},
    "Tagged": TaggedValue {
        tag: !tag,
        value: Bool(true),
    },
}