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