1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
pub trait CsvParseResult<P, T> {
    fn new(payload_inner: T) -> Self;
    fn into_payload(self) -> P;
}

pub struct CsvParseResultLeft {
    pub(crate) csv_left_right_parse_result: CsvLeftRightParseResult,
}

pub struct CsvParseResultRight {
    pub(crate) csv_left_right_parse_result: CsvLeftRightParseResult,
}

#[derive(Debug, PartialEq, Copy, Clone)]
pub enum CsvLeftRightParseResult {
    Left(RecordHash),
    Right(RecordHash),
}

#[derive(Debug, PartialEq, Copy, Clone)]
pub struct RecordHash {
    pub(crate) key: u64,
    pub(crate) record_hash: u64,
    pub(crate) pos: Position,
}

impl RecordHash {
    pub(crate) fn new(key: u64, record_hash: u64, pos: Position) -> Self {
        Self {
            key,
            record_hash,
            pos,
        }
    }
}

#[derive(Debug, PartialEq, Copy, Clone)]
pub(crate) struct Position {
    pub byte_offset: u64,
    pub line: u64,
}

impl Position {
    pub fn new(byte_offset: u64, line: u64) -> Self {
        Self { byte_offset, line }
    }
}

#[allow(clippy::from_over_into)]
impl Into<csv::Position> for Position {
    fn into(self) -> csv::Position {
        let mut csv_pos = csv::Position::new();
        std::mem::replace(
            &mut csv_pos
                .set_byte(self.byte_offset)
                .set_line(self.line)
                .set_record(self.line - 1),
            csv::Position::new(),
        )
    }
}