| @@ -29,19 +29,34 @@ impl<'event> File<'event> { · 28 unmodified lines |
| 29 | .expect("BUG: Section did not have id from lookup") | 29 | .expect("BUG: Section did not have id from lookup") |
| 30 | .to_mut(nl)) | 30 | .to_mut(nl)) |
| 31 | } | 31 | } |
| 32 | | 32 | /// Returns an mutable section with a given `name` and optional `subsection_name`, _if it exists_, or create a new section. |
| 33 | /// Returns an mutable section with a given `name` and optional `subsection_name`, _if it exists_. | | |
| 34 | pub fn section_mut_or_create_new<'a>( | 33 | pub fn section_mut_or_create_new<'a>( |
| 35 | &'a mut self, | 34 | &'a mut self, |
| 36 | name: impl AsRef<str>, | 35 | name: impl AsRef<str>, |
| 37 | subsection_name: Option<&str>, | 36 | subsection_name: Option<&str>, |
| | 37 | ) -> Result<SectionMut<'a, 'event>, section::header::Error> { |
| | 38 | self.section_mut_or_create_new_filter(name, subsection_name, &mut |_| true) |
| | 39 | } |
| | 40 | |
| | 41 | /// Returns an mutable section with a given `name` and optional `subsection_name`, _if it exists_ **and** passes `filter`, or create |
| | 42 | /// a new section. |
| | 43 | pub fn section_mut_or_create_new_filter<'a>( |
| | 44 | &'a mut self, |
| | 45 | name: impl AsRef<str>, |
| | 46 | subsection_name: Option<&str>, |
| | 47 | filter: &mut MetadataFilter, |
| 38 | ) -> Result<SectionMut<'a, 'event>, section::header::Error> { | 48 | ) -> Result<SectionMut<'a, 'event>, section::header::Error> { |
| 39 | let name = name.as_ref(); | 49 | let name = name.as_ref(); |
| 40 | match self | 50 | match self |
| 41 | .section_ids_by_name_and_subname(name.as_ref(), subsection_name) | 51 | .section_ids_by_name_and_subname(name.as_ref(), subsection_name) |
| 42 | .map(|it| it.rev().next().expect("BUG: Section lookup vec was empty")) | 52 | .ok() |
| 43 | { | 53 | .and_then(|it| { |
| 44 | Ok(id) => { | 54 | it.rev().find(|id| { |
| | 55 | let s = &self.sections[id]; |
| | 56 | filter(s.meta()) |
| | 57 | }) |
| | 58 | }) { |
| | 59 | Some(id) => { |
| 45 | let nl = self.detect_newline_style_smallvec(); | 60 | let nl = self.detect_newline_style_smallvec(); |
| 46 | Ok(self | 61 | Ok(self |
| 47 | .sections | 62 | .sections |
| @@ -49,7 +64,7 @@ impl<'event> File<'event> { · 1 unmodified line |
| 49 | .expect("BUG: Section did not have id from lookup") | 64 | .expect("BUG: Section did not have id from lookup") |
| 50 | .to_mut(nl)) | 65 | .to_mut(nl)) |
| 51 | } | 66 | } |
| 52 | Err(_) => self.new_section(name.to_owned(), subsection_name.map(|n| Cow::Owned(n.to_owned()))), | 67 | None => self.new_section(name.to_owned(), subsection_name.map(|n| Cow::Owned(n.to_owned()))), |
| 53 | } | 68 | } |
| 54 | } | 69 | } |
| 55 | | 70 | |