#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Delimiter {
#[default]
Comma,
Tab,
Pipe,
}
impl Delimiter {
pub fn as_char(self) -> char {
match self {
Delimiter::Comma => ',',
Delimiter::Tab => '\t',
Delimiter::Pipe => '|',
}
}
}
#[derive(Debug, Clone, Default)]
pub struct EncodeOptions {
pub delimiter: Option<Delimiter>,
pub length_marker: Option<char>,
pub indent: Option<usize>,
}
impl EncodeOptions {
pub fn new() -> Self {
Self::default()
}
pub fn delimiter(mut self, delimiter: Delimiter) -> Self {
self.delimiter = Some(delimiter);
self
}
pub fn length_marker(mut self, marker: char) -> Self {
self.length_marker = Some(marker);
self
}
pub fn indent(mut self, indent: usize) -> Self {
self.indent = Some(indent);
self
}
pub fn get_delimiter(&self) -> char {
self.delimiter.unwrap_or_default().as_char()
}
pub fn get_indent(&self) -> usize {
self.indent.unwrap_or(2)
}
}
#[derive(Debug, Clone, Default)]
pub struct DecodeOptions {
pub indent: Option<usize>,
pub strict: Option<bool>,
}
impl DecodeOptions {
pub fn new() -> Self {
Self::default()
}
pub fn indent(mut self, indent: usize) -> Self {
self.indent = Some(indent);
self
}
pub fn strict(mut self, strict: bool) -> Self {
self.strict = Some(strict);
self
}
pub fn get_indent(&self) -> usize {
self.indent.unwrap_or(2)
}
pub fn get_strict(&self) -> bool {
self.strict.unwrap_or(true)
}
}