toonify_core/
options.rs

1/// Sets the delimiter used for document-level quoting decisions and the default
2/// delimiter emitted by array headers.
3#[derive(Clone, Copy, Debug, Eq, PartialEq)]
4pub enum Delimiter {
5    Comma,
6    Tab,
7    Pipe,
8}
9
10impl Delimiter {
11    pub(crate) fn as_char(self) -> char {
12        match self {
13            Delimiter::Comma => ',',
14            Delimiter::Tab => '\t',
15            Delimiter::Pipe => '|',
16        }
17    }
18
19    pub(crate) fn bracket_suffix(self) -> &'static str {
20        match self {
21            Delimiter::Comma => "",
22            Delimiter::Tab => "\t",
23            Delimiter::Pipe => "|",
24        }
25    }
26
27    pub(crate) fn separator(self) -> &'static str {
28        match self {
29            Delimiter::Comma => ",",
30            Delimiter::Tab => "\t",
31            Delimiter::Pipe => "|",
32        }
33    }
34}
35
36#[derive(Clone, Copy, Debug, Eq, PartialEq)]
37pub enum KeyFoldingMode {
38    Off,
39    Safe { flatten_depth: Option<usize> },
40}
41
42impl KeyFoldingMode {
43    pub(crate) fn flatten_depth(self) -> Option<usize> {
44        match self {
45            KeyFoldingMode::Off => None,
46            KeyFoldingMode::Safe { flatten_depth } => flatten_depth.or(Some(usize::MAX)),
47        }
48    }
49
50    pub(crate) fn is_enabled(self) -> bool {
51        !matches!(self, KeyFoldingMode::Off)
52    }
53}
54
55#[derive(Clone, Debug)]
56pub struct EncoderOptions {
57    pub indent: usize,
58    pub document_delimiter: Delimiter,
59    pub key_folding: KeyFoldingMode,
60}
61
62impl Default for EncoderOptions {
63    fn default() -> Self {
64        Self {
65            indent: 2,
66            document_delimiter: Delimiter::Comma,
67            key_folding: KeyFoldingMode::Off,
68        }
69    }
70}
71
72#[derive(Clone, Copy, Debug, Eq, PartialEq)]
73pub enum PathExpansionMode {
74    Off,
75    Safe,
76}
77
78#[derive(Clone, Debug)]
79pub struct DecoderOptions {
80    pub indent: usize,
81    pub strict: bool,
82    pub expand_paths: PathExpansionMode,
83}
84
85impl Default for DecoderOptions {
86    fn default() -> Self {
87        Self {
88            indent: 2,
89            strict: true,
90            expand_paths: PathExpansionMode::Off,
91        }
92    }
93}