Function marked_yaml::from_node

source ยท
pub fn from_node<'de, T>(node: &'de Node) -> Result<T, FromNodeError>
where T: Deserialize<'de>,
Available on crate feature serde only.
Expand description

Deserialize some Node into the requisite type

This permits deserialisation of Nodes 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";
let node = marked_yaml::parse_yaml(0, YAML).unwrap();
#[derive(Deserialize)]
struct Greeting {
    hello: Spanned<String>,
}
let greets: Greeting = marked_yaml::from_node(&node).unwrap();
let start = greets.hello.span().start().unwrap();
assert_eq!(start.line(), 1);
assert_eq!(start.column(), 8);