pub fn parse<'a>(
on: &'a str,
cb: impl for<'b> FnMut(&'b [YAMLKey<'a>], RootYAMLValue<'a>),
) -> Result<(), YAMLParseError>Expand description
If you want to return early (not parse the whole input) use parse_with_exit_signal
ยงErrors
Returns an error if it tries to parse invalid YAML input
Examples found in repository?
examples/main.rs (lines 36-38)
3fn main() {
4 let example = r#"
5person:
6 name: John Doe
7 description: |
8 something here
9 that spans multiple lines
10 age: 30
11 something:
12 x: true
13 address:
14 street: 123 Main St
15 city: Example City
16places:
17 list: ["something", "here"]
18 inner:
19 x: string
20"#
21 .trim_start();
22
23 let source = if let Some(path) = std::env::args().nth(1) {
24 std::fs::read_to_string(path).unwrap()
25 } else {
26 example.to_owned()
27 };
28
29 // let second_arg = std::env::args().nth(2);
30 // let mode = second_arg
31 // .and_then(|arg| {
32 // matches!(arg.as_str(), "--verbose" | "--text").then_some(arg[2..].to_owned())
33 // })
34 // .unwrap_or_default();
35
36 parse_yaml(&source, |keys, value| {
37 eprintln!("{keys:?} -> {value:?}");
38 })
39 .unwrap();
40}