Module nondestructive::yaml

source ·
Expand description

Support for non-destructive YAML editing.

YAML is parsed with from_slice, which returns a Document. Documents are serialized through their std::fmt::Display and Document::write_to implementations.

With serde support enabled, Document can also be serialized through serde.

§Specification compliance

This parser does not strictly adhere to the YAML specification.

In particular:

  • We support any form of indentation, not just spaces.
  • Neither input nor output is not required to be UTF-8.
  • Keys in Mappings can be anything, the only requirement is that they are succeeded by a colon (:).
  • Sequences can also be anything, everything after the - is used as a value.

This means that we will validly parse both spec and non-spec compliant YAML. They key here is that editing performed by this crate is non-destructive. So if the source is spec compliant YAML, then we will produce spec compliant YAML. If the source is not spec compliant YAML we will produce similarly non-spec compliant YAML.

If you want to ensure that valid YAML is produced, we recommend that you enable the serde feature and use a crate such serde-yaml. But keep in mind that it will not preserve the original structure of the document. See the serde module for how this is done.


§Serde support

Serde is supported for Document and Value through the serde feature, see the serde module for documentation.

§Examples

use anyhow::Context;
use nondestructive::yaml;

let doc = yaml::from_slice("32")?;
assert_eq!(doc.as_ref().as_u32(), Some(32));

Modules§

Structs§

Enums§

  • An enum which helps to externally discriminate the interior type of a Value.
  • An enum which helps to externally discriminate the interior type of a ValueMut.
  • The kind of a block.
  • The kind of a multiline string.
  • The kind of an Error.
  • The kind of a null value.
  • Separator to use when separating the value from its key or sequence marker.
  • The kind of a string.

Functions§