1use std::fmt::Error;
2use std::fmt::{Display, Formatter};
3
4pub struct Process {
5 pub user: String,
6 pub pid: String,
7 pub cpu: Option<String>,
8 pub memory: Option<String>,
9 pub vsz: Option<String>,
10 pub rss: Option<String>,
11 pub tty: Option<String>,
12 pub stat: Option<String>,
13 pub start: Option<String>,
14 pub time: Option<String>,
15 pub command: String,
16}
17
18#[derive(Serialize, Deserialize, Debug)]
19#[allow(non_snake_case)]
20pub struct Top {
21 pub Titles: Vec<String>,
22 pub Processes: Vec<Vec<String>>,
23}
24
25impl Display for Process {
26 fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
27 let mut s = String::new();
28
29 s.push_str(&*self.user.clone());
30
31 s.push(',');
32 s.push_str(&*self.pid.clone());
33
34 if let Some(v) = self.cpu.clone() {
35 s.push(',');
36 s.push_str(&*v);
37 }
38
39 if let Some(v) = self.memory.clone() {
40 s.push(',');
41 s.push_str(&*v);
42 }
43
44 if let Some(v) = self.vsz.clone() {
45 s.push(',');
46 s.push_str(&*v);
47 }
48
49 if let Some(v) = self.rss.clone() {
50 s.push(',');
51 s.push_str(&*v);
52 }
53
54 if let Some(v) = self.tty.clone() {
55 s.push(',');
56 s.push_str(&*v);
57 }
58
59 if let Some(v) = self.stat.clone() {
60 s.push(',');
61 s.push_str(&*v);
62 }
63
64 if let Some(v) = self.start.clone() {
65 s.push(',');
66 s.push_str(&*v);
67 }
68
69 if let Some(v) = self.time.clone() {
70 s.push(',');
71 s.push_str(&*v);
72 }
73
74 s.push(',');
75 s.push_str(&*self.command.clone());
76
77 write!(f, "{}", s)
78 }
79}