pub fn to_node(any: &impl Serialize) -> Result<Node, SerdeError>
This is supported on crate feature
serde
only.Expand description
Serialize data into Node
.
If a serializable data is provide, it should be able to transform into YAML format.
use serde::Serialize;
use yaml_peg::{serialize::to_node, node};
#[derive(Serialize)]
struct Member<'a> {
name: &'a str,
married: bool,
age: u8,
}
let officer = Member { name: "Bob", married: true, age: 46 };
let officer_yaml = node!({
"name" => "Bob",
"married" => true,
"age" => 46,
});
assert_eq!(officer_yaml, to_node(&officer).unwrap());
There is another version for multi-thread reference counter: to_arc_node
.