#[derive(Debug, Clone)]
pub struct IracingSession {
pub raw_yaml: serde_yaml::Value,
}
impl IracingSession {
pub fn from_yaml(yaml_str: &str) -> Option<Self> {
let raw_yaml: serde_yaml::Value = serde_yaml::from_str(yaml_str).ok()?;
Some(Self { raw_yaml })
}
pub fn get_value(&self, path: &str) -> Option<String> {
let mut current = &self.raw_yaml;
for part in path.split('.') {
if let Some(open_idx) = part.find('[') {
let close_idx = part.find(']')?;
if close_idx != part.len() - 1 {
return None;
}
let field = &part[..open_idx];
let index: usize = part[open_idx + 1..close_idx].parse().ok()?;
current = current.get(field)?.get(index)?;
continue;
}
current = current.get(part)?;
}
match current {
serde_yaml::Value::String(s) => Some(s.clone()),
serde_yaml::Value::Number(n) => Some(n.to_string()),
serde_yaml::Value::Bool(b) => Some(b.to_string()),
_ => None,
}
}
}