#cd #cd-rom #dvd #cup-holder

eject

A crate to control the tray of your CD drive

2 releases

0.1.1 Sep 5, 2022
0.1.0 Aug 31, 2022

#859 in Hardware support

Download history 2/week @ 2024-10-22 34/week @ 2024-10-29 24/week @ 2024-11-05 12/week @ 2024-11-12 21/week @ 2024-11-19 26/week @ 2024-11-26 25/week @ 2024-12-03 45/week @ 2024-12-10 18/week @ 2024-12-17 5/week @ 2024-12-24 7/week @ 2025-01-07 8/week @ 2025-01-14 23/week @ 2025-01-21 523/week @ 2025-01-28 457/week @ 2025-02-04

1,014 downloads per month
Used in 3 crates (via playdate-device)

MIT license

41KB
971 lines

Eject

crates.io version crates.io downloads docs.rs

A Rust library to control the tray of your CD drive.

Currently supporting Windows and Linux.

Features

  • Find installed drives.
  • Open, close and lock the tray.
  • Query current tray position and whether there's a disc inside.

Examples

Basic usage

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()?;

Find all CD drives

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()?;
}

Get drive status

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"),
}

Dependencies

~2–38MB
~522K SLoC