Function marked_yaml::from_yaml

source ·
pub fn from_yaml<T>(source: usize, yaml: &str) -> Result<T, FromYamlError>
Available on crate feature serde only.
Expand description

Deserialize some YAML into the requisite type

This permits deserialisation of a YAML string into any structure which serde can deserialize. In addition, if any part of the type tree is Spanned then the spans are provided from the requisite marked node.

const YAML: &str = "hello: world\n";
#[derive(Deserialize)]
struct Greeting {
    hello: Spanned<String>,
}
let greets: Greeting = marked_yaml::from_yaml(0, YAML).unwrap();
let start = greets.hello.span().start().unwrap();
assert_eq!(start.line(), 1);
assert_eq!(start.column(), 8);