1#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
5pub enum Delimiter {
6 #[default]
8 Comma,
9 Tab,
11 Pipe,
13}
14
15impl Delimiter {
16 pub fn as_char(self) -> char {
18 match self {
19 Delimiter::Comma => ',',
20 Delimiter::Tab => '\t',
21 Delimiter::Pipe => '|',
22 }
23 }
24}
25
26#[derive(Debug, Clone, Default)]
28pub struct EncodeOptions {
29 pub delimiter: Option<Delimiter>,
31 pub length_marker: Option<char>,
33 pub indent: Option<usize>,
35}
36
37impl EncodeOptions {
38 pub fn new() -> Self {
40 Self::default()
41 }
42
43 pub fn delimiter(mut self, delimiter: Delimiter) -> Self {
45 self.delimiter = Some(delimiter);
46 self
47 }
48
49 pub fn length_marker(mut self, marker: char) -> Self {
51 self.length_marker = Some(marker);
52 self
53 }
54
55 pub fn indent(mut self, indent: usize) -> Self {
57 self.indent = Some(indent);
58 self
59 }
60
61 pub fn get_delimiter(&self) -> char {
63 self.delimiter.unwrap_or_default().as_char()
64 }
65
66 pub fn get_indent(&self) -> usize {
68 self.indent.unwrap_or(2)
69 }
70}
71
72#[derive(Debug, Clone, Default)]
74pub struct DecodeOptions {
75 pub indent: Option<usize>,
77 pub strict: Option<bool>,
79}
80
81impl DecodeOptions {
82 pub fn new() -> Self {
84 Self::default()
85 }
86
87 pub fn indent(mut self, indent: usize) -> Self {
89 self.indent = Some(indent);
90 self
91 }
92
93 pub fn strict(mut self, strict: bool) -> Self {
95 self.strict = Some(strict);
96 self
97 }
98
99 pub fn get_indent(&self) -> usize {
101 self.indent.unwrap_or(2)
102 }
103
104 pub fn get_strict(&self) -> bool {
106 self.strict.unwrap_or(true)
107 }
108}