use crate::{file::init, parse::EventRef};
#[derive(Clone, Copy, Default)]
pub struct Options<'a> {
pub includes: init::includes::Options<'a>,
pub lossy: bool,
pub ignore_io_errors: bool,
}
impl Options<'_> {
pub(crate) fn to_event_filter(self) -> Option<fn(EventRef<'_>) -> bool> {
if self.lossy {
Some(discard_nonessential_events)
} else {
None
}
}
}
fn discard_nonessential_events(e: EventRef<'_>) -> bool {
match e {
EventRef::Whitespace(_) | EventRef::Comment { .. } | EventRef::Newline(_) => false,
EventRef::SectionHeader { .. }
| EventRef::SectionValueName(_)
| EventRef::KeyValueSeparator
| EventRef::Value(_)
| EventRef::ValueNotDone(_)
| EventRef::ValueDone(_) => true,
}
}