csv_nose/sample.rs
1/// Sample size configuration for sniffing.
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub enum SampleSize {
4 /// Sample a specific number of records.
5 Records(usize),
6 /// Sample a specific number of bytes.
7 Bytes(usize),
8 /// Read the entire file.
9 All,
10}
11
12impl Default for SampleSize {
13 fn default() -> Self {
14 // Default to 100 records which is reasonable for most files
15 SampleSize::Records(100)
16 }
17}
18
19impl SampleSize {
20 /// Returns the number of records to sample, or None for All.
21 pub fn records(&self) -> Option<usize> {
22 match self {
23 SampleSize::Records(n) => Some(*n),
24 _ => None,
25 }
26 }
27
28 /// Returns the number of bytes to sample, or None for other modes.
29 pub fn bytes(&self) -> Option<usize> {
30 match self {
31 SampleSize::Bytes(n) => Some(*n),
32 _ => None,
33 }
34 }
35}
36
37/// Date format preference for ambiguous date parsing.
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
39pub enum DatePreference {
40 /// Day-Month-Year format (e.g., 31/12/2023).
41 DmyFormat,
42 /// Month-Day-Year format (e.g., 12/31/2023).
43 #[default]
44 MdyFormat,
45}
46
47impl DatePreference {
48 /// Returns true if day comes before month in ambiguous dates.
49 pub fn is_dmy(&self) -> bool {
50 matches!(self, DatePreference::DmyFormat)
51 }
52}