mod utils;
use {
anstream::println,
compris::{normal::*, parse::*, path::*, *},
depiction::*,
};
pub fn main() {
let yaml = r#"hello:
world:
10: # note that this is an integer map key, not a list index!
how:
- are you:
doing
"#;
let variant = without_annotations!(Parser::new(Format::YAML).parse_string(yaml).expect("parse"));
let found_value = traverse!(variant, "hello", "world", 10, "how", 0, "are you").expect("traverse");
utils::heading("found by macro", true);
found_value.print_default_depiction();
let mut path = normal_vec!["hello", "world", 10];
path.push(normal!("how"));
let found_value = variant.traverse(path.iter()).expect("traverse");
utils::heading("found by array", false);
found_value.print_default_depiction();
let result = traverse!(variant, "hello", "world", "how", "are you");
utils::heading("did we find anything? (nope!)", false);
println!("{:?}", result);
match found_value {
Variant::Text(text) => {
utils::heading("it matches text", false);
println!("{}", text);
}
Variant::Integer(_) => {}
_ => (),
}
if let Ok(string) = <&str>::try_from(found_value) {
utils::heading("it can be converted to a string", false);
println!("{}", string);
} else if i64::try_from(found_value).is_ok() {
}
let found_value = traverse!(variant, "hello", "world", 10, "how", 0, "are you").expect("traverse");
let route = Path::find(&variant, found_value).expect("find");
utils::heading("route to found value", false);
route.print_default_depiction();
}