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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
use std::ops::{Add, AddAssign};
use std::time::Duration;
use util::NiceDuration;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde1", derive(Serialize))]
pub struct Stats {
elapsed: NiceDuration,
searches: u64,
searches_with_match: u64,
bytes_searched: u64,
bytes_printed: u64,
matched_lines: u64,
matches: u64,
}
impl Add for Stats {
type Output = Stats;
fn add(self, rhs: Stats) -> Stats {
self + &rhs
}
}
impl<'a> Add<&'a Stats> for Stats {
type Output = Stats;
fn add(self, rhs: &'a Stats) -> Stats {
Stats {
elapsed: NiceDuration(self.elapsed.0 + rhs.elapsed.0),
searches: self.searches + rhs.searches,
searches_with_match:
self.searches_with_match + rhs.searches_with_match,
bytes_searched: self.bytes_searched + rhs.bytes_searched,
bytes_printed: self.bytes_printed + rhs.bytes_printed,
matched_lines: self.matched_lines + rhs.matched_lines,
matches: self.matches + rhs.matches,
}
}
}
impl AddAssign for Stats {
fn add_assign(&mut self, rhs: Stats) {
*self += &rhs;
}
}
impl<'a> AddAssign<&'a Stats> for Stats {
fn add_assign(&mut self, rhs: &'a Stats) {
self.elapsed.0 += rhs.elapsed.0;
self.searches += rhs.searches;
self.searches_with_match += rhs.searches_with_match;
self.bytes_searched += rhs.bytes_searched;
self.bytes_printed += rhs.bytes_printed;
self.matched_lines += rhs.matched_lines;
self.matches += rhs.matches;
}
}
impl Stats {
pub fn new() -> Stats {
Stats::default()
}
pub fn elapsed(&self) -> Duration {
self.elapsed.0
}
pub fn searches(&self) -> u64 {
self.searches
}
pub fn searches_with_match(&self) -> u64 {
self.searches_with_match
}
pub fn bytes_searched(&self) -> u64 {
self.bytes_searched
}
pub fn bytes_printed(&self) -> u64 {
self.bytes_printed
}
pub fn matched_lines(&self) -> u64 {
self.matched_lines
}
pub fn matches(&self) -> u64 {
self.matches
}
pub fn add_elapsed(&mut self, duration: Duration) {
self.elapsed.0 += duration;
}
pub fn add_searches(&mut self, n: u64) {
self.searches += n;
}
pub fn add_searches_with_match(&mut self, n: u64) {
self.searches_with_match += n;
}
pub fn add_bytes_searched(&mut self, n: u64) {
self.bytes_searched += n;
}
pub fn add_bytes_printed(&mut self, n: u64) {
self.bytes_printed += n;
}
pub fn add_matched_lines(&mut self, n: u64) {
self.matched_lines += n;
}
pub fn add_matches(&mut self, n: u64) {
self.matches += n;
}
}