History

return key iterator

Edward Shen committed 5 years ago

Commit adfa4601 parent 81271e21 file · +6 −4Browse files

Showing the changes to git-config/src (1 of 1 file). Show all

Unified · Split

git-config/src/file.rs+6−4
@@ -222,7 +222,7 @@ impl<'borrow, 'event> MutableSection<'borrow, 'event> { · 221 unmodified lines
222222 self.section.0.drain(start..=end);
223223 }
224224
225− fn set(&mut self, index: usize, key: Key<'event>, value: Vec<u8>) {
225+ fn set_internal(&mut self, index: usize, key: Key<'event>, value: Vec<u8>) {
226226 self.section
227227 .0
228228 .insert(index, Event::Value(Cow::Owned(value)));
@@ -350,8 +350,10 @@ impl<'event> SectionBody<'event> { · 121 unmodified lines
350350 }
351351
352352 /// Returns an iterator visiting all keys in order.
353− pub fn keys(&self) -> impl Iterator<Item = &Event<'event>> {
354− self.0.iter().filter(|e| matches!(e, Event::Key(_)))
353+ pub fn keys(&self) -> impl Iterator<Item = &Key<'event>> {
354+ self.0
355+ .iter()
356+ .filter_map(|e| if let Event::Key(k) = e { Some(k) } else { None })
355357 }
356358
357359 /// Checks if the section contains the provided key.
@@ -825,7 +827,7 @@ impl MutableValue<'_, '_, '_> { · 467 unmodified lines
825827 }
826828 self.size = 3;
827829 self.section
828− .set(self.index, Key(Cow::Owned(self.key.to_string())), input);
830+ .set_internal(self.index, Key(Cow::Owned(self.key.to_string())), input);
829831 }
830832
831833 /// Removes the value. Does nothing when called multiple times in