Struct csv_diff::csv_diff::CsvByteDiffBuilder
source ยท 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_to_diff_byte_records()?;
diff_byte_records.sort_by_line();
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ยง
sourceยงimpl<T> CsvByteDiffBuilder<T>where
T: CsvHashTaskSpawner,
impl<T> CsvByteDiffBuilder<T>where
T: CsvHashTaskSpawner,
pub fn primary_key_columns( self, columns: impl IntoIterator<Item = usize> ) -> Self
sourceยงimpl CsvByteDiffBuilder<CsvHashTaskSpawnerRayon>
impl CsvByteDiffBuilder<CsvHashTaskSpawnerRayon>
pub fn new() -> Self
pub fn rayon_thread_pool(self, thread_pool: Arc<ThreadPool>) -> Self
pub fn build( self ) -> Result<CsvByteDiff<CsvHashTaskSpawnerRayon>, CsvByteDiffBuilderError>
Trait Implementationsยง
sourceยงimpl<T: Debug + CsvHashTaskSpawner> Debug for CsvByteDiffBuilder<T>
impl<T: Debug + CsvHashTaskSpawner> Debug for CsvByteDiffBuilder<T>
sourceยงimpl<T: Default + CsvHashTaskSpawner> Default for CsvByteDiffBuilder<T>
impl<T: Default + CsvHashTaskSpawner> Default for CsvByteDiffBuilder<T>
sourceยงfn default() -> CsvByteDiffBuilder<T>
fn default() -> CsvByteDiffBuilder<T>
Returns the โdefault valueโ for a type. Read more
Auto Trait Implementationsยง
impl<T> !RefUnwindSafe for CsvByteDiffBuilder<T>
impl<T> Send for CsvByteDiffBuilder<T>where
T: Send,
impl<T> Sync for CsvByteDiffBuilder<T>where
T: Sync,
impl<T> Unpin for CsvByteDiffBuilder<T>where
T: Unpin,
impl<T> !UnwindSafe for CsvByteDiffBuilder<T>
Blanket Implementationsยง
sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more