Skip to main content

qemu_command_builder/args/
usb.rs

1use crate::parsers::ARG_USBDEVICE;
2use crate::to_command::ToCommand;
3use proptest_derive::Arbitrary;
4use std::str::FromStr;
5
6/// Legacy `-usbdevice` device names accepted by QEMU.
7#[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq, Arbitrary)]
8pub enum USBDevice {
9    Braille,
10    Keyboard,
11    Mouse,
12    Tablet,
13    WacomTablet,
14}
15
16impl ToCommand for USBDevice {
17    fn command(&self) -> String {
18        ARG_USBDEVICE.to_string()
19    }
20    fn to_args(&self) -> Vec<String> {
21        let mut args = vec![];
22
23        match self {
24            USBDevice::Braille => args.push("braille".to_string()),
25            USBDevice::Keyboard => args.push("keyboard".to_string()),
26            USBDevice::Mouse => args.push("mouse".to_string()),
27            USBDevice::Tablet => args.push("tablet".to_string()),
28            USBDevice::WacomTablet => args.push("wacom-tablet".to_string()),
29        }
30        args
31    }
32}
33
34impl FromStr for USBDevice {
35    type Err = String;
36
37    fn from_str(s: &str) -> Result<Self, Self::Err> {
38        match s {
39            "braille" => Ok(Self::Braille),
40            "keyboard" => Ok(Self::Keyboard),
41            "mouse" => Ok(Self::Mouse),
42            "tablet" => Ok(Self::Tablet),
43            "wacom-tablet" => Ok(Self::WacomTablet),
44            other => Err(format!("unsupported usbdevice: {other}")),
45        }
46    }
47}