1#[derive(Debug, Clone, PartialEq, Eq, Default)]
5pub struct MatchResult {
6 matched: bool,
7 matched_observations: Vec<usize>,
8}
9
10impl MatchResult {
11 pub fn no_match() -> Self {
13 MatchResult {
14 matched: false,
15 matched_observations: Vec::new(),
16 }
17 }
18
19 pub fn matched(observations: Vec<usize>) -> Self {
21 MatchResult {
22 matched: true,
23 matched_observations: observations,
24 }
25 }
26
27 pub fn is_match(&self) -> bool {
29 self.matched
30 }
31
32 pub fn observations(&self) -> &[usize] {
34 &self.matched_observations
35 }
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 #[test]
43 fn no_match_is_false() {
44 let r = MatchResult::no_match();
45 assert!(!r.is_match());
46 assert!(r.observations().is_empty());
47 }
48
49 #[test]
50 fn matched_records_observations() {
51 let r = MatchResult::matched(vec![0, 2]);
52 assert!(r.is_match());
53 assert_eq!(r.observations(), &[0, 2]);
54 }
55}