pub trait InsertImmutable { fn insert(&self, item: Item) -> bool; } mod trait_impls { use std::{cell::RefCell, collections::HashSet, hash::Hash}; use dashmap::DashSet; use super::InsertImmutable; use crate::cache; impl InsertImmutable for DashSet { fn insert(&self, item: T) -> bool { self.insert(item) } } impl InsertImmutable for RefCell> { fn insert(&self, item: T) -> bool { self.borrow_mut().insert(item) } } } pub struct Chunks { pub size: usize, pub iter: I, } impl Iterator for Chunks where I: Iterator, { type Item = Vec; fn next(&mut self) -> Option { let mut res = Vec::with_capacity(self.size); let mut items_left = self.size; for item in &mut self.iter { res.push(item); items_left -= 1; if items_left == 0 { break; } } (!res.is_empty()).then(|| res) } }