krata/xsd/examples/list.rs

36 lines
974 B
Rust
Raw Normal View History

2024-01-08 20:43:16 +00:00
use xsd::bus::XsdBusError;
use xsd::client::XsdClient;
2024-01-08 22:16:33 +00:00
use xsd::sys::XSD_ERROR_EINVAL;
2024-01-08 20:43:16 +00:00
fn list_recursive(client: &mut XsdClient, level: usize, path: &str) -> Result<(), XsdBusError> {
let children = match client.list(path) {
Ok(children) => children,
Err(error) => {
2024-01-08 22:16:33 +00:00
return if error.to_string() == XSD_ERROR_EINVAL.error {
Ok(())
} else {
Err(error)
}
2024-01-08 20:43:16 +00:00
}
};
for child in children {
let full = format!("{}/{}", if path == "/" { "" } else { path }, child);
2024-01-08 20:43:16 +00:00
let value = client.read(full.as_str())?;
println!(
"{}{} = {:?}",
" ".repeat(level),
child,
String::from_utf8(value)?
);
2024-01-08 20:43:16 +00:00
list_recursive(client, level + 1, full.as_str())?;
}
Ok(())
}
fn main() -> Result<(), XsdBusError> {
let mut client = XsdClient::new()?;
list_recursive(&mut client, 0, "/")?;
Ok(())
}