pub struct CsvByteDiffBuilder<T: CsvHashTaskSpawner> { /* private fields */ }
Expand description

Create a CsvByteDiff with configuration options.

Example: create a CsvByteDiff, where column 1 and column 3 are treated as a compound primary key.

use csv_diff::{csv_diff::{CsvByteDiff, CsvByteDiffBuilder}, csv::Csv};
use csv_diff::diff_row::{ByteRecordLineInfo, DiffByteRecord};
use csv_diff::diff_result::DiffByteRecords;
use std::convert::TryInto;
// some csv data with a header, where the first column and third column represent a compound key
let csv_data_left = "\
    id,name,commit_sha\n\
    1,lemon,efae52\n\
    2,strawberry,a33411"; // this csv line is seen as "Deleted" and not "Modified"
                          // because "id" and "commit_sha" are different and both columns
                          // _together_ represent the primary key
let csv_data_right = "\
    id,name,commit_sha\n\
    1,lemon,efae52\n\
    2,strawberry,ddef23"; // this csv line is seen as "Added" and not "Modified",
                          // because "id" and "commit_sha" are different and both columns
                          // _together_ represent the primary key

let csv_byte_diff = CsvByteDiffBuilder::new()
    .primary_key_columns(vec![0usize, 2])
    .build()?;

let mut diff_byte_records: DiffByteRecords = csv_byte_diff
    .diff(
        Csv::with_reader(csv_data_left.as_bytes()),
        Csv::with_reader(csv_data_right.as_bytes()),
    )
    .try_into()?;

let diff_byte_rows = diff_byte_records.as_slice();

assert_eq!(
    diff_byte_rows,
    &[
        DiffByteRecord::Delete(ByteRecordLineInfo::new(
            csv::ByteRecord::from(vec!["2", "strawberry", "a33411"]),
            3
        ),),
        DiffByteRecord::Add(ByteRecordLineInfo::new(
            csv::ByteRecord::from(vec!["2", "strawberry", "ddef23"]),
            3
        ),)
    ]
);
Ok(())

Implementationsยง

Trait Implementationsยง

Formats the value using the given formatter. Read more
Returns the โ€œdefault valueโ€ for a type. Read more

Auto Trait Implementationsยง

Blanket Implementationsยง

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.