1use crate::calls::callstack::CallStack;
2use crate::calls::CallStacks;
3use crate::quote;
4pub trait Filter {
5 fn execute(&self, cs: &CallStack) -> bool;
6}
7
8pub struct TopFrameFilter<'a> {
9 matcher: &'a dyn quote::MatchQuote,
10}
11
12impl<'a> TopFrameFilter<'a> {
13 pub fn new(m: &'a dyn quote::MatchQuote) -> Self {
14 TopFrameFilter { matcher: m }
15 }
16}
17
18impl<'a> Filter for TopFrameFilter<'a> {
19 fn execute(&self, cs: &CallStack) -> bool {
20 match cs.get(0) {
21 None => false,
22 Some(f) => self.matcher.match_quote(&f.raw),
23 }
24 }
25}
26
27pub struct AnyFrameFilter<'a> {
28 matcher: &'a dyn quote::MatchQuote,
29}
30impl<'a> AnyFrameFilter<'a> {
31 pub fn new(m: &'a dyn quote::MatchQuote) -> Self {
32 AnyFrameFilter { matcher: m }
33 }
34}
35
36impl<'a> Filter for AnyFrameFilter<'a> {
37 fn execute(&self, cs: &CallStack) -> bool {
38 cs.iter().any(|e| self.matcher.match_quote(&e.raw))
39 }
40}
41
42pub fn filter(css: &CallStacks, filter: &dyn Filter) -> CallStacks {
43 let mut css_res = CallStacks::new();
44 for cs in css.iter() {
45 if filter.execute(cs) {
46 css_res.push(cs.clone());
47 }
48 }
49 css_res
50}