Expand description
§Marked YAML
Currently this library only supports parsing YAML from strings, but this is sufficient for most users’ purposes. We would not recommend an un-streamed processing engine for massive data anyway.
To parse some YAML you simply need to:
let node = marked_yaml::parse_yaml(0, r#"
toplevel: must be a mapping
but:
- it
- may
- contain lists
and:
mappings: are permitted
as: sub-mappings
"#);
assert!(node.is_ok());
Parsing a valid YAML string may fail because marked_yaml
adds some
additional constraints:
- The top level of the YAML MUST be a mapping or a sequence.
- Mapping keys MUST be scalars (strings).
- Aliases and anchors MAY NOT be used (though this limit may be lifted in the future).
In addition, you can convert between marked_yaml::Node
and yaml_rust::Yaml
though doing so will not give you any useful markers.
§Serde
Should you so choose, you may use serde to deserialise YAML
strings directly into structures, any amount of which could be annotated
with the Spanned
type to capture information about where the value came
from in the input.
let YAML = "Daniel: Author\nUser: Not Author\n";
let roles: HashMap<Spanned<String>, Spanned<String>> = from_yaml(0, YAML).unwrap();
assert_eq!(roles["Daniel"], "Author");
assert_eq!(roles["User"].span().start().copied(), Some(Marker::new(0, 2, 7)));
You do not have to have all values Spanned
, and you can deserialize from an already
parsed set of nodes with from_node
instead.
Empty scalars can be deserialized to empty sequences, maps, the unit type ()
and structs with a #[serde(default)]
attribute.
Modules§
Structs§
- From
Node Error serde
- The error returned by
from_node
- Loader
Options - Options for loading YAML
- Marker
- A marker for a YAML node
- Span
- The span for a YAML marked node
- Spanned
serde
- Wrapper which can be used when deserialising data from
Node
Enums§
- Error
serde
- Errors which can come from deserialisation
- From
Yaml Error serde
- Errors which can occur when deserialising from YAML
- Load
Error - Errors which can occur during loading of YAML
- Node
- A marked YAML node
Functions§
- from_
node serde
- Deserialize some
Node
into the requisite type - from_
yaml serde
- Deserialize some YAML into the requisite type
- from_
yaml_ with_ options serde
- Deserialize some YAML into the requisite type
- parse_
yaml - Parse YAML from a string and return a Node representing the content.
- parse_
yaml_ with_ options - Parse YAML from a string and return a Node representing the content.