html: rm FilteredEvents

no longer useful as no peeking is needed, use simple early exit instead
This commit is contained in:
Noah Hellman 2023-03-17 19:05:56 +01:00
parent 336927faef
commit f5724fcc9c

View file

@ -49,24 +49,8 @@ enum Raw {
Other, Other,
} }
struct FilteredEvents<I> {
events: I,
}
impl<'s, I: Iterator<Item = Event<'s>>> Iterator for FilteredEvents<I> {
type Item = Event<'s>;
fn next(&mut self) -> Option<Self::Item> {
let mut ev = self.events.next();
while matches!(ev, Some(Event::Blankline | Event::Escape)) {
ev = self.events.next();
}
ev
}
}
struct Writer<'s, I: Iterator<Item = Event<'s>>, W> { struct Writer<'s, I: Iterator<Item = Event<'s>>, W> {
events: std::iter::Peekable<FilteredEvents<I>>, events: I,
out: W, out: W,
raw: Raw, raw: Raw,
img_alt_text: usize, img_alt_text: usize,
@ -80,7 +64,7 @@ struct Writer<'s, I: Iterator<Item = Event<'s>>, W> {
impl<'s, I: Iterator<Item = Event<'s>>, W: std::fmt::Write> Writer<'s, I, W> { impl<'s, I: Iterator<Item = Event<'s>>, W: std::fmt::Write> Writer<'s, I, W> {
fn new(events: I, out: W) -> Self { fn new(events: I, out: W) -> Self {
Self { Self {
events: FilteredEvents { events }.peekable(), events,
out, out,
raw: Raw::None, raw: Raw::None,
img_alt_text: 0, img_alt_text: 0,
@ -94,6 +78,10 @@ impl<'s, I: Iterator<Item = Event<'s>>, W: std::fmt::Write> Writer<'s, I, W> {
fn write(&mut self) -> std::fmt::Result { fn write(&mut self) -> std::fmt::Result {
while let Some(e) = self.events.next() { while let Some(e) = self.events.next() {
if matches!(&e, Event::Blankline | Event::Escape) {
continue;
}
let close_para = self.close_para; let close_para = self.close_para;
if close_para { if close_para {
self.close_para = false; self.close_para = false;