1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::fmt;
#[cfg_attr(feature = "io", derive(Deserialize, Serialize))]
#[derive(Clone, Default, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct Stats {
pub blanks: usize,
pub code: usize,
pub comments: usize,
pub lines: usize,
pub name: String,
}
impl Stats {
pub fn new<S: Into<String>>(name: S) -> Self {
Stats { name: name.into(), ..Self::default() }
}
}
impl fmt::Display for Stats {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let name_length = self.name.len();
let name = if name_length == 25 {
self.name.clone()
} else if self.name.len() > 24 {
let mut name = String::from("|");
name.push_str(&self.name[self.name.len() - 24..]);
name
} else {
self.name.clone()
};
write!(f,
" {: <25} {:>12} {:>12} {:>12} {:>12}",
name,
self.lines,
self.code,
self.comments,
self.blanks)
}
}