gix_config/file/init/
types.rs1use crate::{file::init, parse, parse::EventRef, path::interpolate};
2
3#[derive(Debug, thiserror::Error)]
5#[expect(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 #[error(transparent)]
14 Span(#[from] parse::span::Error),
15}
16
17#[derive(Clone, Copy, Default)]
19pub struct Options<'a> {
20 pub includes: init::includes::Options<'a>,
22 pub lossy: bool,
27 pub ignore_io_errors: bool,
31}
32
33impl Options<'_> {
34 pub(crate) fn to_event_filter(self) -> Option<fn(EventRef<'_>) -> bool> {
35 if self.lossy {
36 Some(discard_nonessential_events)
37 } else {
38 None
39 }
40 }
41}
42
43fn discard_nonessential_events(e: EventRef<'_>) -> bool {
44 match e {
45 EventRef::Whitespace(_) | EventRef::Comment { .. } | EventRef::Newline(_) => false,
46 EventRef::SectionHeader { .. }
47 | EventRef::SectionValueName(_)
48 | EventRef::KeyValueSeparator
49 | EventRef::Value(_)
50 | EventRef::ValueNotDone(_)
51 | EventRef::ValueDone(_) => true,
52 }
53}