Crates.io | eject |
lib.rs | eject |
version | 0.1.1 |
source | src |
created_at | 2022-08-31 07:46:49.048846 |
updated_at | 2022-09-05 08:10:51.42078 |
description | A crate to control the tray of your CD drive |
homepage | |
repository | https://github.com/matix64/eject-rs |
max_upload_size | |
id | 655535 |
size | 41,180 |
A Rust library to control the tray of your CD drive.
Currently supporting Windows and Linux.
use eject::{device::Device, discovery::cd_drives};
// Open the drive at this path
let cdrom = Device::open("/dev/cdrom")?;
// Or get the first one available
let cdrom_path = cd_drives().next().unwrap();
let cdrom = Device::open(&cdrom_path)?;
// Open the tray
cdrom.eject()?;
use eject::{device::Device, discovery::cd_drives};
// Get the paths of all CD drives
for path in cd_drives() {
// Print the path
println!("{:?}", path);
// Access the drive
let drive = Device::open(path)?;
// Close its tray
drive.retract()?;
}
use eject::{device::{Device, DriveStatus}, discovery::cd_drives};
// Open a drive
let drive = Device::open("/dev/cdrom")?;
// Print its status
match drive.status()? {
DriveStatus::Empty =>
println!("The tray is closed and no disc is inside"),
DriveStatus::TrayOpen =>
println!("The tray is open"),
DriveStatus::NotReady =>
println!("This drive is not ready yet"),
DriveStatus::Loaded =>
println!("There's a disc inside"),
}