Function marked_yaml::loader::parse_yaml

source ·
pub fn parse_yaml<S>(source: usize, yaml: S) -> Result<Node, LoadError>
where S: AsRef<str>,
Expand description

Parse YAML from a string and return a Node representing the content.

When parsing YAML, the source is stored into all markers which are in the node spans. This means that later if you only have a node, you can determine which source it came from without needing complex lifetimes to bind strings or other non-copy data to nodes.

This function requires that the top level be a mapping, but the returned type here is the generic Node enumeration to make it potentially easier for callers to use. Regardless, it’s always possible to treat the returned node as a mapping node without risk of panic.

If you wish to load a sequence instead of a mapping, then you will need to use parse_yaml_with_options to request that.

let node = parse_yaml(0, include_str!("../examples/everything.yaml"))
    .unwrap()
    .as_mapping()
    .unwrap();