gix_config/file/init/
types.rs1use crate::{file::init, parse, parse::Event, path::interpolate};
2
3#[derive(Debug, thiserror::Error)]
5#[allow(missing_docs)]
6pub enum Error {
7 #[error(transparent)]
8 Parse(#[from] parse::Error),
9 #[error(transparent)]
10 Interpolate(#[from] interpolate::Error),
11 #[error(transparent)]
12 Includes(#[from] init::includes::Error),
13}
14
15#[derive(Clone, Copy, Default)]
17pub struct Options<'a> {
18 pub includes: init::includes::Options<'a>,
20 pub lossy: bool,
25 pub ignore_io_errors: bool,
29}
30
31impl Options<'_> {
32 pub(crate) fn to_event_filter(self) -> Option<fn(&Event<'_>) -> bool> {
33 if self.lossy {
34 Some(discard_nonessential_events)
35 } else {
36 None
37 }
38 }
39}
40
41fn discard_nonessential_events(e: &Event<'_>) -> bool {
42 match e {
43 Event::Whitespace(_) | Event::Comment(_) | Event::Newline(_) => false,
44 Event::SectionHeader(_)
45 | Event::SectionValueName(_)
46 | Event::KeyValueSeparator
47 | Event::Value(_)
48 | Event::ValueNotDone(_)
49 | Event::ValueDone(_) => true,
50 }
51}