deser-yaml
YAML support for
deser. YAML is full of surprises
(is no a string or a boolean? is 1.10 a version or a float?). This
crate aims to be correct rather than clever: it passes the official test
suite, lets you pick YAML 1.1 or 1.2 semantics, and the serializer quotes
exactly what needs quoting so that what you write is what other readers
(including PyYAML) read back.
use ;
let config: Config = from_str.unwrap;
assert_eq!;
// strings that look like other types are quoted
assert_eq!;
// errors point at the problem
let err =
.unwrap_err;
assert_eq!;
Features:
- Anchors and aliases (with a limit against alias bombs), tags,
!!binarybytes,!!timestampdate-times and multi-document streams. - Configurable output: indentation, quoting, flow or block collections (also per value through hints), literal block scalars.
- Source locations in errors and through
deser_location::Spanned. - Deeply nested input does not overflow the stack.
- Streams of documents are read with a
Deserializerand written with aSerializer. from_readerandto_writerwork withstd::io, and the configurations read and write streams of documents withdeser::ioor async runtimes (deser-tokio) while only buffering one document at a time.
Conformance
The parser is written from scratch against the official YAML test suite and the YAML schema tests. The serializer writes block style YAML that reads back as the same values, also for YAML 1.1 readers. The conformance tests serialize every valid document of the test suite with several configurations and read it back.
Running the Tests
The test data is vendored in tests/data and can be updated with
scripts/update-yaml-test-data.sh. Run the suite with:
Pass test ids or parts of test descriptions to only run some tests and to see the details of failures, including known ones:
Tests that are expected to fail are listed in
tests/yaml_test_suite_known_failures.txt. The run fails if a test fails
that is not listed there or if a listed test passes. After fixing tests,
update the list with:
DESER_YAML_BLESS=1