pub struct CsvByteDiffLocal<T: CsvHashTaskSpawnerLocal> { /* private fields */ }
Expand description
Compare two CSVs eagerly with each other (for the lazy/iterator-based variant, see CsvByteDiff
).
Use this instead of CsvByteDiff
, when your CSV data is a local reference and you don’t own it.
This requires your CSV data to be Seek
able. If it isn’t Seek
able out of the box, it might still auto implement
the trait CsvReadSeek
(see Csv::with_reader_seek
).
If your CSV data can’t be made Seek
able, consider using CsvByteDiff
instead.
CsvByteDiffLocal
uses scoped threads internally for comparison.
By default, it uses rayon’s scoped threads within a rayon thread pool.
See also rayon_thread_pool
on CsvByteDiffLocalBuilder
for using an existing rayon thread-pool
when creating CsvByteDiffLocal
.
§Example: create CsvByteDiffLocal
with default values and compare two CSVs byte-wise eagerly
use csv_diff::{csv_diff::CsvByteDiffLocal, csv::Csv};
use csv_diff::diff_row::{ByteRecordLineInfo, DiffByteRecord};
use std::collections::HashSet;
use std::iter::FromIterator;
// some csv data with a header, where the first column is a unique id
let csv_data_left = "id,name,kind\n\
1,lemon,fruit\n\
2,strawberry,fruit";
let csv_data_right = "id,name,kind\n\
1,lemon,fruit\n\
2,strawberry,nut";
let csv_byte_diff = CsvByteDiffLocal::new()?;
let mut diff_byte_records = csv_byte_diff.diff(
Csv::with_reader_seek(csv_data_left.as_bytes()),
Csv::with_reader_seek(csv_data_right.as_bytes()),
)?;
let diff_byte_rows = diff_byte_records.as_slice();
assert_eq!(
diff_byte_rows,
&[DiffByteRecord::Modify {
delete: ByteRecordLineInfo::new(
csv::ByteRecord::from(vec!["2", "strawberry", "fruit"]),
3
),
add: ByteRecordLineInfo::new(csv::ByteRecord::from(vec!["2", "strawberry", "nut"]), 3),
field_indices: vec![2]
}]
);
Ok(())
Implementations§
Source§impl CsvByteDiffLocal<CsvHashTaskSpawnerLocalRayon<'_>>
impl CsvByteDiffLocal<CsvHashTaskSpawnerLocalRayon<'_>>
Sourcepub fn new() -> Result<Self, CsvDiffNewError>
pub fn new() -> Result<Self, CsvDiffNewError>
Constructs a new CsvByteDiffLocal<CsvHashTaskSpawnerRayon<'_>>
with a default configuration.
The values in the first column of each CSV will be declared as the primary key, in order
to match the CSV records against each other.
During the construction, a new rayon thread-pool
is created, which will be used later during the comparison of CSVs.
If you need to have more control over the configuration of CsvByteDiffLocal<CsvHashTaskSpawnerRayon<'_>>
,
consider using a CsvByteDiffLocalBuilder
instead.
Source§impl<T> CsvByteDiffLocal<T>where
T: CsvHashTaskSpawnerLocal,
impl<T> CsvByteDiffLocal<T>where
T: CsvHashTaskSpawnerLocal,
Sourcepub fn diff<R: Read + Seek + Send>(
&self,
csv_left: Csv<R>,
csv_right: Csv<R>,
) -> Result<DiffByteRecords>
pub fn diff<R: Read + Seek + Send>( &self, csv_left: Csv<R>, csv_right: Csv<R>, ) -> Result<DiffByteRecords>
Compares csv_left
with csv_right
and returns a csv::Result
with the CSV byte records that are different.
Csv<R>
is a wrapper around a CSV reader with some configuration options.
§Example
use csv_diff::{csv_diff::CsvByteDiffLocal, csv::Csv};
use csv_diff::diff_row::{ByteRecordLineInfo, DiffByteRecord};
use std::collections::HashSet;
use std::iter::FromIterator;
// some csv data with a header, where the first column is a unique id
let csv_data_left = "id,name,kind\n\
1,lemon,fruit\n\
2,strawberry,fruit";
let csv_data_right = "id,name,kind\n\
1,lemon,fruit\n\
2,strawberry,nut";
let csv_byte_diff = CsvByteDiffLocal::new()?;
let mut diff_byte_records = csv_byte_diff.diff(
Csv::with_reader_seek(csv_data_left.as_bytes()),
Csv::with_reader_seek(csv_data_right.as_bytes()),
)?;
diff_byte_records.sort_by_line();
let diff_byte_rows = diff_byte_records.as_slice();
assert_eq!(
diff_byte_rows,
&[DiffByteRecord::Modify {
delete: ByteRecordLineInfo::new(
csv::ByteRecord::from(vec!["2", "strawberry", "fruit"]),
3
),
add: ByteRecordLineInfo::new(csv::ByteRecord::from(vec!["2", "strawberry", "nut"]), 3),
field_indices: vec![2]
}]
);
Ok(())
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for CsvByteDiffLocal<T>where
T: Freeze,
impl<T> RefUnwindSafe for CsvByteDiffLocal<T>where
T: RefUnwindSafe,
impl<T> Send for CsvByteDiffLocal<T>where
T: Send,
impl<T> Sync for CsvByteDiffLocal<T>where
T: Sync,
impl<T> Unpin for CsvByteDiffLocal<T>where
T: Unpin,
impl<T> UnwindSafe for CsvByteDiffLocal<T>where
T: UnwindSafe,
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more