From b73d97f24afd73e0ea55bc463d4fc55f5f023b1b Mon Sep 17 00:00:00 2001 From: Edward Shen Date: Tue, 9 Mar 2021 11:08:57 -0500 Subject: [PATCH] return key iterator --- src/file.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/file.rs b/src/file.rs index 215f529..b9b6eca 100644 --- a/src/file.rs +++ b/src/file.rs @@ -222,7 +222,7 @@ impl<'borrow, 'event> MutableSection<'borrow, 'event> { self.section.0.drain(start..=end); } - fn set(&mut self, index: usize, key: Key<'event>, value: Vec) { + fn set_internal(&mut self, index: usize, key: Key<'event>, value: Vec) { self.section .0 .insert(index, Event::Value(Cow::Owned(value))); @@ -350,8 +350,10 @@ impl<'event> SectionBody<'event> { } /// Returns an iterator visiting all keys in order. - pub fn keys(&self) -> impl Iterator> { - self.0.iter().filter(|e| matches!(e, Event::Key(_))) + pub fn keys(&self) -> impl Iterator> { + self.0 + .iter() + .filter_map(|e| if let Event::Key(k) = e { Some(k) } else { None }) } /// Checks if the section contains the provided key. @@ -825,7 +827,7 @@ impl MutableValue<'_, '_, '_> { } self.size = 3; self.section - .set(self.index, Key(Cow::Owned(self.key.to_string())), input); + .set_internal(self.index, Key(Cow::Owned(self.key.to_string())), input); } /// Removes the value. Does nothing when called multiple times in