qemu_command_builder/
device.rs1use bon::Builder;
2
3use crate::to_command::ToCommand;
4
5#[derive(Default, Builder)]
12pub struct Device {
13 device: String,
14 properties: Vec<(String, String)>,
15}
16
17impl Device {
18 pub fn new<S: AsRef<str>>(device: S) -> Self {
19 Device {
20 device: device.as_ref().to_string(),
21 properties: Default::default(),
22 }
23 }
24 pub fn add_prop<S: AsRef<str>>(&mut self, key: S, value: S) -> &mut Self {
25 self.properties
26 .push((key.as_ref().to_string(), value.as_ref().to_string()));
27 self
28 }
29}
30impl ToCommand for Device {
31 fn to_command(&self) -> Vec<String> {
32 let mut cmd = vec![];
33
34 cmd.push("-device".to_string());
35 let mut args = vec![self.device.clone()];
36
37 for (prop_key, prop_value) in &self.properties {
38 args.push(format!("{}={}", prop_key, prop_value));
39 }
40 cmd.push(args.join(","));
41
42 cmd
43 }
44}