blob: 563f157f2b678613d8f8c9a39784dcb7a5abe441 (
plain)
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
|
pub struct DoubleBuffer<T> {
a1: Vec<T>,
a2: Vec<T>,
switch: bool,
}
impl<T> DoubleBuffer<T> {
pub fn new(a1: Vec<T>, a2: Vec<T>) -> Self {
Self { a1, a2, switch: false }
}
pub fn switch(&mut self) {
self.switch = !self.switch;
}
pub fn first(&self) -> &Vec<T> {
if self.switch { &self.a2 } else { &self.a1 }
}
pub fn first_mut(&mut self) -> &mut Vec<T> {
if self.switch { &mut self.a2 } else { &mut self.a1 }
}
pub fn second(&self) -> &Vec<T> {
if self.switch { &self.a1 } else { &self.a2 }
}
pub fn second_mut(&mut self) -> &mut Vec<T> {
if self.switch { &mut self.a1 } else { &mut self.a2 }
}
}
|