You say you use yaml-rust, but I'm assuming you are actually using serde_yaml, which makes more sense in the context of your question. You can iteratively call Value::get till you get to the required depth, like this, for example:
use serde_yaml::{from_str, Value, Index};
fn index_yaml<'a>(yaml: &'a Value, indices: &[&dyn Index]) -> Option<&'a Value> {
let mut current_depth = yaml;
for i in indices {
current_depth = current_depth.get(i)?;
}
Some(current_depth)
}
fn main() {
let raw = "foo: [list1, list2]";
let yaml: Value = from_str(raw).unwrap();
assert_eq!(yaml["foo"][0].as_str().unwrap(), "list1");
let indices: Vec<&dyn Index> = vec![&"foo", &0];
let list1 = index_yaml(&yaml, &indices).unwrap();
assert_eq!(list1, "list1");
}