struct Pair { iter: I } impl Pair { fn new(iter: I) -> Self { Self { iter } } } impl Iterator for Pair { type Item = (I::Item, I::Item); fn next(&mut self) -> Option { Some((self.iter.next()?, self.iter.next()?)) } } use std::collections::HashMap; fn main() { let v = vec!["homer", "25", "bart", "55", "monty", "101"]; let h: HashMap<_, _> = Pair::new(v.into_iter()).filter_map(|(c, s)| match s.parse::() { Ok(score) if score <= 100 => Some((c, score)), _ => None, }).collect(); println!("{h:?}"); }