use std::{cell::RefCell, collections::VecDeque, rc::Rc}; #[derive(Clone)] pub struct Tasks(Rc>>) where TaskType: Clone; impl Tasks { pub fn new() -> Self { Self(Rc::new(RefCell::new(VecDeque::new()))) } pub fn push(&self, task: TaskType) { self.0.borrow_mut().push_back(task); } pub fn drain(&mut self) -> VecDeque { let mut tasks = self.0.borrow_mut(); std::mem::take(&mut *tasks) } } impl Default for Tasks { fn default() -> Self { Self::new() } }