csv_lib/models/
csv_config.rs

1use crate::decoders::decoders::Encoding;
2
3#[derive(Debug,Clone)]
4#[allow(dead_code)]
5/// ## CsvConfig Struct
6///
7/// - Stores the config used to read a CSV File.
8pub struct CsvConfig {
9    /// Force function to use memchr3. is more compatible, but don't take advantage of NEON / AVX2 feature
10    pub force_memcach3 : bool,
11    /// A u8 with the byte of the chars that can be considered as delimiter.
12    pub delimiter: u8,
13    /// Allow to define a string delimiter. Use `0u8` if you want to disable it
14    pub string_separator: u8,
15    /// Defines the line break char
16    pub line_break: u8,
17    /// Defines de encoding used to open the file.
18    pub encoding: Encoding,
19}
20
21
22impl Default for CsvConfig {
23    /// ## Default for `CsvConfig`
24    /// - Implements the default construction for struct CsvConfig
25    /// ### Code Example:
26    /// ```
27    /// //Import zone
28    /// use csv_lib::decoders::decoders::Encoding;
29    /// use csv_lib::models::csv_config::CsvConfig;
30    ///
31    /// //Default CsvConfig construction
32    /// let a = CsvConfig{
33    ///  force_memcach3 : false,
34    ///   delimiter : b';',
35    ///   string_separator:0u8,
36    ///   line_break: b'\n',
37    ///   encoding : Encoding::Windows1252
38    /// };
39    /// ```
40    fn default() -> Self {
41        Self {
42            force_memcach3 : false,
43            delimiter : b';',
44            string_separator:0u8,
45            line_break: b'\n',
46            encoding: Encoding::Windows1252,
47        }
48    }
49}
50
51impl CsvConfig {
52
53    #[allow(dead_code)]
54    #[inline(always)]
55    /// ## New Function:
56    /// - Creates a new instance of the struct `CsvConfig`
57    pub fn new(
58        delimiter: u8,
59        string_separators: u8,
60        line_break: u8,
61        encoding: Encoding,
62        force_memcach3: bool
63    ) -> Self {
64        Self {
65            force_memcach3,
66            delimiter,
67            string_separator: string_separators,
68            line_break,
69            encoding,
70        }
71    }
72}