rs_docker/
process.rs

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_str(",");
32        s.push_str(&*self.pid.clone());
33
34        match self.cpu.clone() {
35            Some(v) => {
36                s.push_str(",");
37                s.push_str(&*v);
38            }
39            None => {}
40        }
41
42        match self.memory.clone() {
43            Some(v) => {
44                s.push_str(",");
45                s.push_str(&*v);
46            }
47            None => {}
48        }
49
50        match self.vsz.clone() {
51            Some(v) => {
52                s.push_str(",");
53                s.push_str(&*v);
54            }
55            None => {}
56        }
57
58        match self.rss.clone() {
59            Some(v) => {
60                s.push_str(",");
61                s.push_str(&*v);
62            }
63            None => {}
64        }
65
66        match self.tty.clone() {
67            Some(v) => {
68                s.push_str(",");
69                s.push_str(&*v);
70            }
71            None => {}
72        }
73
74        match self.stat.clone() {
75            Some(v) => {
76                s.push_str(",");
77                s.push_str(&*v);
78            }
79            None => {}
80        }
81
82        match self.start.clone() {
83            Some(v) => {
84                s.push_str(",");
85                s.push_str(&*v);
86            }
87            None => {}
88        }
89
90        match self.time.clone() {
91            Some(v) => {
92                s.push_str(",");
93                s.push_str(&*v);
94            }
95            None => {}
96        }
97
98        s.push_str(",");
99        s.push_str(&*self.command.clone());
100
101        write!(f, "{}", s)
102    }
103}