pub struct DoubleBuffer { a1: Vec, a2: Vec, switch: bool, } impl DoubleBuffer { pub fn new(a1: Vec, a2: Vec) -> Self { Self { a1, a2, switch: false } } pub fn switch(&mut self) { self.switch = !self.switch; } pub fn first(&self) -> &Vec { if self.switch { &self.a2 } else { &self.a1 } } pub fn first_mut(&mut self) -> &mut Vec { if self.switch { &mut self.a2 } else { &mut self.a1 } } pub fn second(&self) -> &Vec { if self.switch { &self.a1 } else { &self.a2 } } pub fn second_mut(&mut self) -> &mut Vec { if self.switch { &mut self.a1 } else { &mut self.a2 } } }