File: loop.rs

package info (click to toggle)
rust-udisks2 0.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 604 kB
  • sloc: xml: 511; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 864 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::ffi::CString;

#[tokio::main]
async fn main() -> udisks2::Result<()> {
    let client = udisks2::Client::new().await?;

    for object in client
        .object_manager()
        .get_managed_objects()
        .await?
        .into_iter()
        .filter_map(|(object_path, _)| client.object(object_path).ok())
    {
        //only use objects that have a drive
        let Ok(fs) = object.filesystem().await else {
            continue;
        };

        // print path and mount point
        for mount_point in fs
            .mount_points()
            .await
            .unwrap()
            .iter()
            .filter_map(|p| CString::from_vec_with_nul(p.to_vec()).ok())
            .filter_map(|p| p.to_str().map(|p| p.to_string()).ok())
        {
            println!("{}:{:?}", object.object_path(), mount_point);
        }
    }
    Ok(())
}