Skip to main content

list_drives/
list_drives.rs

1/// Lists all optical drives detected on the system and whether they contain an audio CD.
2use cd_da_reader::CdReader;
3
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5    let drives = CdReader::list_drives()?;
6
7    if drives.is_empty() {
8        println!("No optical drives found.");
9        return Ok(());
10    }
11
12    println!("Found {} drive(s):\n", drives.len());
13    for drive in &drives {
14        let name = drive.display_name.as_deref().unwrap_or("(unknown)");
15        let status = if drive.has_audio_cd {
16            "audio CD inserted"
17        } else {
18            "no audio CD"
19        };
20        println!(
21            "Drive: {}, name: {}, status: [{}]",
22            drive.path, name, status
23        );
24    }
25
26    Ok(())
27}