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 status = if drive.has_audio_cd {
15            "audio CD inserted"
16        } else {
17            "no audio CD"
18        };
19        println!("Drive: {}, status: [{status}]", drive.path);
20    }
21
22    Ok(())
23}