qemu_command_builder/
tpmdev.rs1use std::path::PathBuf;
2
3use bon::Builder;
4
5use crate::to_command::ToCommand;
6
7#[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq, Default, Builder)]
8pub struct Passthrough {
9 id: String,
10 path: Option<PathBuf>,
11 cancel_path: Option<PathBuf>,
12}
13
14impl ToCommand for Passthrough {
15 fn to_command(&self) -> Vec<String> {
16 let mut cmd = vec![];
17
18 let mut args = vec![
19 "passthrough".to_string(),
20 format!("id={}", self.id.to_string()),
21 ];
22
23 if let Some(path) = &self.path {
24 args.push(format!("path={}", path.display()));
25 }
26 if let Some(cancel_path) = &self.cancel_path {
27 args.push(format!("cancel-path={}", cancel_path.display()));
28 }
29
30 cmd.push(args.join(","));
31 cmd
32 }
33}
34
35#[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq, Default, Builder)]
36pub struct Emulator {
37 id: String,
38 chardev: String,
39}
40
41impl ToCommand for Emulator {
42 fn to_command(&self) -> Vec<String> {
43 let mut cmd = vec![];
44
45 let args = [
46 "emulator".to_string(),
47 format!("id={}", self.id),
48 format!("chardev={}", self.chardev),
49 ];
50
51 cmd.push(args.join(","));
52 cmd
53 }
54}
55
56#[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
57pub enum TpmDev {
58 Passthrough(Passthrough),
59 Emulator(Emulator),
60}
61
62impl ToCommand for TpmDev {
63 fn to_command(&self) -> Vec<String> {
64 let mut cmd = vec![];
65
66 cmd.push("-tpmdev".to_string());
67
68 match self {
69 TpmDev::Passthrough(p) => cmd.append(&mut p.to_command()),
70 TpmDev::Emulator(e) => cmd.append(&mut e.to_command()),
71 }
72
73 cmd
74 }
75}