mirror of
				https://github.com/edera-dev/krata.git
				synced 2025-11-04 07:39:39 +00:00 
			
		
		
		
	async-ify xenstore and xenclient
This commit is contained in:
		@ -1,9 +1,10 @@
 | 
			
		||||
use futures::executor::block_on;
 | 
			
		||||
use xenstore::client::{XsdClient, XsdInterface};
 | 
			
		||||
use xenstore::error::Result;
 | 
			
		||||
use xenstore::sys::XSD_ERROR_EINVAL;
 | 
			
		||||
 | 
			
		||||
fn list_recursive(client: &mut XsdClient, level: usize, path: &str) -> Result<()> {
 | 
			
		||||
    let children = match client.list(path) {
 | 
			
		||||
    let children = match block_on(client.list(path)) {
 | 
			
		||||
        Ok(children) => children,
 | 
			
		||||
        Err(error) => {
 | 
			
		||||
            return if error.to_string() == XSD_ERROR_EINVAL.error {
 | 
			
		||||
@ -16,20 +17,16 @@ fn list_recursive(client: &mut XsdClient, level: usize, path: &str) -> Result<()
 | 
			
		||||
 | 
			
		||||
    for child in children {
 | 
			
		||||
        let full = format!("{}/{}", if path == "/" { "" } else { path }, child);
 | 
			
		||||
        let value = client.read(full.as_str())?;
 | 
			
		||||
        println!(
 | 
			
		||||
            "{}{} = {:?}",
 | 
			
		||||
            " ".repeat(level),
 | 
			
		||||
            child,
 | 
			
		||||
            String::from_utf8(value)?
 | 
			
		||||
        );
 | 
			
		||||
        let value = block_on(client.read_string(full.as_str()))?.expect("expected value");
 | 
			
		||||
        println!("{}{} = {:?}", " ".repeat(level), child, value,);
 | 
			
		||||
        list_recursive(client, level + 1, full.as_str())?;
 | 
			
		||||
    }
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn main() -> Result<()> {
 | 
			
		||||
    let mut client = XsdClient::open()?;
 | 
			
		||||
#[tokio::main]
 | 
			
		||||
async fn main() -> Result<()> {
 | 
			
		||||
    let mut client = XsdClient::open().await?;
 | 
			
		||||
    list_recursive(&mut client, 0, "/")?;
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user