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
use crate::Matcher;
#[derive(Debug, PartialEq)]
pub struct Logs<I>(pub Vec<I>);
impl<I: PartialEq + Clone> Logs<I> {
pub(crate) fn push(&mut self, item: I) {
self.0.push(item);
}
pub(crate) fn is_empty(&self) -> bool {
self.0.len() == 0
}
pub(crate) fn filter_matches(&self, matcher: &Matcher<I>) -> Self {
Self(
self.0
.iter()
.filter(|log| matcher.matches(log))
.cloned()
.collect(),
)
}
}
impl<I> Default for Logs<I> {
fn default() -> Self {
Self(Default::default())
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn is_empty() {
assert!(Logs::<u8>(vec![]).is_empty());
assert!(!Logs::<u8>(vec![1]).is_empty());
}
#[test]
fn filter_matches() {
let logs = Logs(vec![1, 2, 2, 3, 4, 2]);
assert_eq!(logs.filter_matches(&Matcher::Eq(2)), Logs(vec![2, 2, 2]));
}
}