rsp_rs/windowing/
window_instance.rs

1// Representing the instance of a Window.
2#[derive(Debug, Clone)]
3pub struct WindowInstance {
4    pub open: i64,
5    pub close: i64,
6    pub has_triggered_and_emitted: bool,
7}
8
9// Implement PartialEq and Eq based only on open and close
10impl PartialEq for WindowInstance {
11    fn eq(&self, other: &Self) -> bool {
12        self.open == other.open && self.close == other.close
13    }
14}
15
16impl Eq for WindowInstance {}
17
18// Implement Hash based only on open and close
19impl std::hash::Hash for WindowInstance {
20    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
21        self.open.hash(state);
22        self.close.hash(state);
23    }
24}
25
26impl WindowInstance {
27    pub fn new(open: i64, close: i64) -> Self {
28        Self {
29            open,
30            close,
31            has_triggered_and_emitted: false,
32        }
33    }
34
35    pub fn set_triggered_and_emitted(&mut self, val: bool) {
36        self.has_triggered_and_emitted = val;
37    }
38
39    pub fn is_same_window(&self, other: &WindowInstance) -> bool {
40        self.open == other.open && self.close == other.close
41    }
42}