2个版本
0.1.1 | 2022年9月5日 |
---|---|
0.1.0 | 2022年8月31日 |
#766 in 硬件支持
241 每月下载次数
在 3 个crate中使用了(via playdate-device)
41KB
971 行
Eject
一个用于控制CD光驱托盘的Rust库。
目前支持Windows和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()?;
查找所有CD驱动器
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"),
}
依赖项
~2–39MB
~578K SLoC