diff -r 3c37cb7bce61 -r a11237723332 rust/hg-core/src/config/mod.rs --- a/rust/hg-core/src/config/mod.rs Wed Jan 25 18:45:38 2023 +0100 +++ b/rust/hg-core/src/config/mod.rs Fri Jan 13 00:07:07 2023 +0100 @@ -510,30 +510,6 @@ &'a self, section: &'a [u8], ) -> impl Iterator + 'a { - // TODO: Use `Iterator`’s `.peekable()` when its `peek_mut` is - // available: - // https://doc.rust-lang.org/nightly/std/iter/struct.Peekable.html#method.peek_mut - struct Peekable { - iter: I, - /// Remember a peeked value, even if it was None. - peeked: Option>, - } - - impl Peekable { - fn new(iter: I) -> Self { - Self { iter, peeked: None } - } - - fn next(&mut self) { - self.peeked = None - } - - fn peek_mut(&mut self) -> Option<&mut I::Item> { - let iter = &mut self.iter; - self.peeked.get_or_insert_with(|| iter.next()).as_mut() - } - } - // Deduplicate keys redefined in multiple layers let mut keys_already_seen = HashSet::new(); let mut key_is_new = @@ -543,12 +519,12 @@ // This is similar to `flat_map` + `filter_map`, except with a single // closure that owns `key_is_new` (and therefore the // `keys_already_seen` set): - let mut layer_iters = Peekable::new( - self.layers - .iter() - .rev() - .map(move |layer| layer.iter_section(section)), - ); + let mut layer_iters = self + .layers + .iter() + .rev() + .map(move |layer| layer.iter_section(section)) + .peekable(); std::iter::from_fn(move || loop { if let Some(pair) = layer_iters.peek_mut()?.find(&mut key_is_new) { return Some(pair);