csv_diff/
csv_parse_result.rs1pub trait CsvParseResult<P, T> {
2 fn new(payload_inner: T) -> Self;
3 fn into_payload(self) -> P;
4}
5
6pub struct CsvParseResultLeft<R> {
7 pub(crate) csv_left_right_parse_result: CsvLeftRightParseResult<R>,
8}
9
10pub struct CsvParseResultRight<R> {
11 pub(crate) csv_left_right_parse_result: CsvLeftRightParseResult<R>,
12}
13
14#[derive(Debug, PartialEq, Copy, Clone)]
15pub enum CsvLeftRightParseResult<R> {
16 Left(R),
17 Right(R),
18}
19
20#[derive(Debug, PartialEq, Copy, Clone)]
21pub(crate) struct RecordHash {
22 pub(crate) key: u128,
23 pub(crate) record_hash: u128,
24}
25
26impl RecordHash {
27 #[inline]
28 pub(crate) fn new(key: u128, record_hash: u128) -> Self {
29 Self { key, record_hash }
30 }
31}
32
33#[derive(Debug, PartialEq, Copy, Clone)]
34pub struct RecordHashWithPosition {
35 pub(crate) record_hash: RecordHash,
36 pub(crate) pos: Position,
37}
38
39impl RecordHashWithPosition {
40 #[inline]
41 pub(crate) fn new(key: u128, record_hash: u128, pos: Position) -> Self {
42 Self {
43 record_hash: RecordHash::new(key, record_hash),
44 pos,
45 }
46 }
47 #[inline]
48 pub(crate) fn key(&self) -> u128 {
49 self.record_hash.key
50 }
51 #[inline]
52 pub(crate) fn record_hash_num(&self) -> u128 {
53 self.record_hash.record_hash
54 }
55}
56
57pub struct CsvByteRecordWithHash {
58 pub(crate) byte_record: csv::Result<csv::ByteRecord>,
59 pub(crate) record_hash: RecordHash,
60}
61
62impl CsvByteRecordWithHash {
63 #[inline]
64 pub(crate) fn new(byte_record: csv::Result<csv::ByteRecord>, record_hash: RecordHash) -> Self {
65 Self {
66 byte_record,
67 record_hash,
68 }
69 }
70}
71
72#[derive(Debug, PartialEq, Copy, Clone)]
73pub(crate) struct Position {
74 pub byte_offset: u64,
75 pub line: u64,
76}
77
78impl Position {
79 #[inline]
80 pub fn new(byte_offset: u64, line: u64) -> Self {
81 Self { byte_offset, line }
82 }
83}
84
85#[allow(clippy::from_over_into)]
86impl Into<csv::Position> for Position {
87 #[inline]
88 fn into(self) -> csv::Position {
89 let mut csv_pos = csv::Position::new();
90 std::mem::replace(
91 csv_pos
92 .set_byte(self.byte_offset)
93 .set_line(self.line)
94 .set_record(self.line - 1),
95 csv::Position::new(),
96 )
97 }
98}