pub fn parse<'a>(
on: &'a str,
cb: impl for<'b> FnMut(&'b [TOMLKey<'a>], RootTOMLValue<'a>),
) -> Result<(), TOMLParseError>
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 TOML input
Examples found in repository?
examples/main.rs (lines 43-45)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
fn main() {
let example = r#"
# This is a TOML document
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00
[database]
enabled = true
ports = [8000, 8001, 8002]
data = [["delta", "phi"], [3.14]]
temp_targets = { cpu = 79.5, case = 72.0 }
[servers]
[servers.alpha]
ip = "10.0.0.1"
role = "frontend"
[servers.beta]
ip = "10.0.0.2"
"#
.trim_start();
let source = if let Some(path) = std::env::args().nth(1) {
std::fs::read_to_string(path).unwrap()
} else {
example.to_owned()
};
// let second_arg = std::env::args().nth(2);
// let mode = second_arg
// .and_then(|arg| {
// matches!(arg.as_str(), "--verbose" | "--text").then_some(arg[2..].to_owned())
// })
// .unwrap_or_default();
parse_toml(&source, |keys, value| {
eprintln!("{keys:?} -> {value:?}");
})
.unwrap();
}